Spaces:
Sleeping
Sleeping
Refactor AgentNode in graph.py to utilize CodeAgent instead of ToolCallingAgent, update prompt template loading to use code_agent.yaml, and enhance step callback logging for improved debugging.
Browse files
graph.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import logging
|
| 2 |
-
from typing import TypedDict
|
| 3 |
from langgraph.graph import StateGraph, END
|
| 4 |
-
from smolagents import ToolCallingAgent, LiteLLMModel
|
| 5 |
from tools import tools
|
| 6 |
import yaml
|
| 7 |
import os
|
|
@@ -25,7 +25,8 @@ class AgentNode:
|
|
| 25 |
# Load default prompt templates from local file
|
| 26 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 27 |
prompts_dir = os.path.join(current_dir, "prompts")
|
| 28 |
-
yaml_path = os.path.join(prompts_dir, "toolcalling_agent.yaml")
|
|
|
|
| 29 |
|
| 30 |
with open(yaml_path, 'r') as f:
|
| 31 |
prompt_templates = yaml.safe_load(f)
|
|
@@ -55,11 +56,25 @@ class AgentNode:
|
|
| 55 |
model_id="ollama/codellama",
|
| 56 |
)
|
| 57 |
|
| 58 |
-
self.agent = ToolCallingAgent(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
max_steps=1,
|
| 60 |
model=self.model,
|
| 61 |
prompt_templates=prompt_templates,
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
)
|
| 64 |
|
| 65 |
def __call__(self, state: AgentState) -> AgentState:
|
|
|
|
| 1 |
import logging
|
| 2 |
+
from typing import Callable, List, Optional, TypedDict
|
| 3 |
from langgraph.graph import StateGraph, END
|
| 4 |
+
from smolagents import CodeAgent, ToolCallingAgent, LiteLLMModel
|
| 5 |
from tools import tools
|
| 6 |
import yaml
|
| 7 |
import os
|
|
|
|
| 25 |
# Load default prompt templates from local file
|
| 26 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 27 |
prompts_dir = os.path.join(current_dir, "prompts")
|
| 28 |
+
# yaml_path = os.path.join(prompts_dir, "toolcalling_agent.yaml")
|
| 29 |
+
yaml_path = os.path.join(prompts_dir, "code_agent.yaml")
|
| 30 |
|
| 31 |
with open(yaml_path, 'r') as f:
|
| 32 |
prompt_templates = yaml.safe_load(f)
|
|
|
|
| 56 |
model_id="ollama/codellama",
|
| 57 |
)
|
| 58 |
|
| 59 |
+
# self.agent = ToolCallingAgent(
|
| 60 |
+
# max_steps=1,
|
| 61 |
+
# model=self.model,
|
| 62 |
+
# prompt_templates=prompt_templates,
|
| 63 |
+
# tools=tools
|
| 64 |
+
# )
|
| 65 |
+
|
| 66 |
+
step_callbacks: Optional[List[Callable]] = [
|
| 67 |
+
lambda step: logger.info(f"Step {step.step_number} completed: {step.action_step.action}")
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
self.agent = CodeAgent(
|
| 71 |
+
add_base_tools=True,
|
| 72 |
max_steps=1,
|
| 73 |
model=self.model,
|
| 74 |
prompt_templates=prompt_templates,
|
| 75 |
+
step_callbacks=step_callbacks,
|
| 76 |
+
tools=tools,
|
| 77 |
+
verbosity_level=logging.DEBUG
|
| 78 |
)
|
| 79 |
|
| 80 |
def __call__(self, state: AgentState) -> AgentState:
|