Skip to content

Instantly share code, notes, and snippets.

@hwchase17
Created February 7, 2024 03:14
Show Gist options
  • Save hwchase17/4e74dcda13e4545e93d26e2047567e0f to your computer and use it in GitHub Desktop.
Save hwchase17/4e74dcda13e4545e93d26e2047567e0f to your computer and use it in GitHub Desktop.

Revisions

  1. hwchase17 created this gist Feb 7, 2024.
    41 changes: 41 additions & 0 deletions coding.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    class AgentState(TypedDict):
    code: str
    tests: str
    errors: Optional[str]

    def initial_writer(state):
    ...
    return {"code": ..., "tests": ...}


    def run_tests(state):
    ...
    # error = None if no errors
    return {"errors": error}


    def reprogram(state):
    ...
    return {"code": ...}


    workflow = StateGraph(AgentState)

    workflow.add_node("initial_writer", initial_writer)
    workflow.add_node("execute_tests", run_tests)
    workflow.add_node("reprogram", reprogram)

    workflow.set_entry_point("initial_writer")

    workflow.add_conditional_edges(
    "execute_tests",
    should_continue,
    {
    "continue": "reprogram",
    "end": END
    }
    )

    workflow.add_edge('initial_writer', 'execute_tests')
    workflow.add_edge('reprogram', 'execute_tests')
    graph = workflow.compile()