Skip to content

Commit b7596df

Browse files
committed
refactor: update content and metadata parameter types in memory_log function to improve type specificity and enhance handling of structured data
1 parent ef18648 commit b7596df

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

src/routing/router.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ def __init__(self):
1414
self.llm = self.model.with_structured_output(Redirection)
1515

1616
def route(self, state: ScoutState) -> Literal["planner", "executor"]:
17-
result = self.llm.invoke({
18-
"messages": [
17+
result = self.llm.invoke([
1918
SystemMessage(content="""
2019
You're a redirection LLM, you determine where does the execution go next.
2120
* recon: reconnaissance agent for information gathering
@@ -25,8 +24,7 @@ def route(self, state: ScoutState) -> Literal["planner", "executor"]:
2524
* If you find that previous agents are already able to find the flag, you should redirect to the end node immediately.
2625
"""),
2726
HumanMessage(content=f"current state: {state}")
28-
]
29-
})
27+
])
3028
return result.dst
3129

3230

src/tool.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ def _ensure_plan_dict(content: Any) -> Dict[str, Any]:
8080
@tool
8181
def memory_log(
8282
action: Literal["store_plan", "get_plan", "list", "store"],
83-
content: Optional[str] = None,
83+
content: Optional[dict[str, Any]] = None,
8484
category: Literal["plan", "finding", "reflection", "note"] = "note",
8585
metadata: Optional[str] = "{}",
8686
) -> str:
8787
"""Memory log tool for LangGraph.
8888
8989
Args:
9090
action (Literal["store_plan", "get_plan", "list", "store"]): The action to perform.
91-
content (Optional[str], optional): The content to store. Defaults to None.
91+
content (Optional[dict[str, Any]], optional): The content to store. Defaults to None.
9292
category (Literal["plan", "finding", "reflection", "note"], optional): The category of the content. Defaults to "note".
93-
metadata (Optional[str], optional): The metadata of the content, should be a JSON string. Defaults to "{}".
93+
metadata (Optional[dict[str, Any]], optional): The metadata of the content. Defaults to {}.
9494
9595
Returns:
9696
The JSON string describing the outcome of the memory operation.
@@ -103,9 +103,8 @@ def memory_log(
103103
if action == "store_plan":
104104
if content is None:
105105
raise ValueError("content is required for store_plan action")
106-
plan_dict = _ensure_plan_dict(content)
107-
save_plan(plan_dict, state=state, store=store)
108-
return json.dumps({"status": "plan_stored", "plan": plan_dict})
106+
save_plan(content, state=state, store=store)
107+
return json.dumps({"status": "plan_stored", "plan": content})
109108

110109
if action == "get_plan":
111110
plan_payload = load_plan(state=state, store=store)
@@ -122,7 +121,7 @@ def memory_log(
122121
entry = {
123122
"timestamp": datetime.utcnow().isoformat(),
124123
"category": category,
125-
"content": str(content),
124+
"content": content,
126125
"metadata": metadata,
127126
}
128127
stored_entry = append_memory_entry(entry, state=state, store=store)

0 commit comments

Comments
 (0)