This commit is contained in:
Harrison Chase
2025-03-10 16:15:27 -07:00
parent ba8f5f437b
commit c63936e348
4 changed files with 21 additions and 16 deletions
+12 -4
View File
@@ -2,6 +2,14 @@
This prebuilt graph is an agent that uses a reflection-style architecture to check and improve an initial agent's output.
## Installation
```
pip install langgraph-reflection
```
## Details
This reflection agent uses two subagents:
- A "main" agent, which is the agent attempting to solve the users task
- A "critique" agent, which checks the main agents work and offers any critiques
@@ -56,8 +64,8 @@ judge_graph = StateGraph(MessagesState).add_node(judge_response)...
# Create reflection graph that combines assistant and judge
reflexion_app = create_reflection_graph(assistant_graph, judge_graph)
result = reflexion_app.invoke({"messages": example_query})
reflection_app = create_reflection_graph(assistant_graph, judge_graph)
result = reflection_app.invoke({"messages": example_query})
```
### Code Validation ([examples/coding.py](examples/coding.py))
@@ -100,8 +108,8 @@ def try_running(state: dict) -> dict | None:
judge_graph = StateGraph(MessagesState).add_node(try_running)...
# Create reflection system that combines code generation and validation
reflexion_app = create_reflection_graph(assistant_graph, judge_graph)
result = reflexion_app.invoke({"messages": example_query})
reflection_app = create_reflection_graph(assistant_graph, judge_graph)
result = reflection_app.invoke({"messages": example_query})
```
The code validation example ensures that generated code is not only syntactically correct but also type-safe and follows best practices through static analysis.
+4 -4
View File
@@ -141,7 +141,7 @@ def create_graphs():
if __name__ == "__main__":
"""Run an example query through the reflexion system."""
"""Run an example query through the reflection system."""
example_query = [
{
"role": "user",
@@ -149,7 +149,7 @@ if __name__ == "__main__":
}
]
print("Running example with reflexion...")
reflexion_app = create_graphs()
result = reflexion_app.invoke({"messages": example_query})
print("Running example with reflection...")
reflection_app = create_graphs()
result = reflection_app.invoke({"messages": example_query})
print("Result:", result)
+5 -5
View File
@@ -80,8 +80,8 @@ judge_graph = (
# Create the complete reflection graph
reflexion_app = create_reflection_graph(assistant_graph, judge_graph)
reflexion_app = reflexion_app.compile()
reflection_app = create_reflection_graph(assistant_graph, judge_graph)
reflection_app = reflection_app.compile()
# Example usage
@@ -94,6 +94,6 @@ if __name__ == "__main__":
}
]
# Process the query through the reflexion system
print("Running example with reflexion...")
result = reflexion_app.invoke({"messages": example_query})
# Process the query through the reflection system
print("Running example with reflection...")
result = reflection_app.invoke({"messages": example_query})
-3
View File
@@ -14,9 +14,6 @@ authors = [{name = "Harrison Chase"}]
[tool.setuptools.packages.find]
where = ["src"]
[tool.uv.sources]
langgraph-reflexion = { workspace = true }
[dependency-groups]
dev = [
"langgraph-reflection",