Skip to content

Instantly share code, notes, and snippets.

@hwchase17
Created February 7, 2024 03:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hwchase17/4e74dcda13e4545e93d26e2047567e0f to your computer and use it in GitHub Desktop.
Save hwchase17/4e74dcda13e4545e93d26e2047567e0f to your computer and use it in GitHub Desktop.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment