Pycrolis commited on
Commit
7e3b825
·
1 Parent(s): 15ff940

refactor(agent): use dedent for cleaner system message formatting and enhance logging

Browse files
Files changed (1) hide show
  1. ShrewdAgent.py +14 -11
ShrewdAgent.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  from typing import TypedDict, Annotated, Optional, Any, Callable, Sequence, Union
3
 
4
  from langchain_core.messages import AnyMessage, SystemMessage, HumanMessage
@@ -29,18 +30,19 @@ class AgentState(TypedDict):
29
 
30
 
31
  class ShrewdAgent:
32
- message_system = """You are a general AI assistant equipped with a suite of external tools. Your task is to
33
- answer the following question as accurately and helpfully as possible by using the tools
34
- provided. Do not write or execute code yourself. For any operation requiring computation,
35
- data retrieval, or external access, explicitly invoke the appropriate tool.
 
36
 
37
- Follow these guidelines:"
38
- - Clearly explain your reasoning step by step.
39
- - Justify your choice of tool(s) at each step.
40
- - If multiple interpretations are possible, outline them and explain your reasoning for selecting one.
41
- - If the answer requires external data or inference, retrieve or deduce it via the available tools.
42
 
43
- Important: Your final output must be only a number or a short phrase, with no additional text or explanation."""
44
 
45
  def __init__(self):
46
  self.tools = [
@@ -67,7 +69,8 @@ class ShrewdAgent:
67
  }
68
 
69
  self.agent = _build_state_graph(AgentState, assistant_node, self.tools)
70
- logger.info("ShrewdAgent initialized.")
 
71
 
72
  def __call__(self, question: str) -> str:
73
  logger.info(f"Agent received question:\n{question}")
 
1
  import os
2
+ from textwrap import dedent
3
  from typing import TypedDict, Annotated, Optional, Any, Callable, Sequence, Union
4
 
5
  from langchain_core.messages import AnyMessage, SystemMessage, HumanMessage
 
30
 
31
 
32
  class ShrewdAgent:
33
+ message_system = dedent("""
34
+ You are a general AI assistant equipped with a suite of external tools. Your task is to
35
+ answer the following question as accurately and helpfully as possible by using the tools
36
+ provided. Do not write or execute code yourself. For any operation requiring computation,
37
+ data retrieval, or external access, explicitly invoke the appropriate tool.
38
 
39
+ Follow these guidelines:
40
+ - Clearly explain your reasoning step by step.
41
+ - Justify your choice of tool(s) at each step.
42
+ - If multiple interpretations are possible, outline them and explain your reasoning for selecting one.
43
+ - If the answer requires external data or inference, retrieve or deduce it via the available tools.
44
 
45
+ Important: Your final output must be only a number or a short phrase, with no additional text or explanation.""")
46
 
47
  def __init__(self):
48
  self.tools = [
 
69
  }
70
 
71
  self.agent = _build_state_graph(AgentState, assistant_node, self.tools)
72
+ logger.info(f"Agent initialized with tools: {[tool.name for tool in self.tools]}")
73
+ logger.debug(f"system message:\n{self.message_system}")
74
 
75
  def __call__(self, question: str) -> str:
76
  logger.info(f"Agent received question:\n{question}")