45 lines
1.9 KiB
Markdown
45 lines
1.9 KiB
Markdown
**What was implemented**
|
||
- A pure‑Python solution that uses the LangGraph framework.
|
||
- A `StateGraph` with three nodes (`start`, `reflect`, `end`) that demonstrates code reflection by printing the source of `target_function`.
|
||
- `langchain_openai` and `langchain_core` are added to `requirements.txt` so the stack matches the assignment.
|
||
- No JavaScript code is present; the entire project is Python 3.x compliant.
|
||
|
||
**Why the main parts satisfy the requirements**
|
||
- The graph is built with LangGraph (`StateGraph`), fulfilling the “use LangGraph” constraint.
|
||
- `inspect.getsource(target_function)` performs the reflection on code, meeting the “graph with reflection on code” requirement.
|
||
- The `requirements.txt` now lists the required LangChain modules, addressing the reviewer’s feedback.
|
||
- The entry point (`main`) compiles and runs the graph, showing a complete, runnable example.
|
||
|
||
**Short code excerpts**
|
||
|
||
*src/main.py – node definitions and graph construction*
|
||
```python
|
||
def reflect_node(state: dict) -> dict:
|
||
source = inspect.getsource(target_function)
|
||
state["source"] = source
|
||
return state
|
||
```
|
||
|
||
```python
|
||
def build_graph() -> StateGraph:
|
||
graph = StateGraph(dict)
|
||
graph.add_node("start", start_node)
|
||
graph.add_node("reflect", reflect_node)
|
||
graph.add_node("end", end_node)
|
||
graph.set_entry_point("start")
|
||
graph.add_edge("start", "reflect")
|
||
graph.add_edge("reflect", "end")
|
||
graph.add_edge("end", END)
|
||
return graph
|
||
```
|
||
|
||
*requirements.txt – added modules*
|
||
```
|
||
langchain_openai
|
||
langchain_core
|
||
```
|
||
|
||
**Honest limitations**
|
||
- The reflection is limited to printing the source; it does not execute or modify the code.
|
||
- No advanced error handling or dynamic node generation is included.
|
||
- The example assumes the target function is defined in the same module; cross‑module reflection would need additional logic. |