WeByT3 commited on
Commit
654f1b2
·
verified ·
1 Parent(s): d716044

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +5 -18
agent.py CHANGED
@@ -10,28 +10,16 @@ from typing import TypedDict, Optional
10
  tools = [add, multiply, divide, subtract, search_wikipedia]
11
 
12
  def build_agent():
13
-
14
- class AgentState(TypedDict):
15
- messages: list # chat history
16
- wiki_table: Optional[str]
17
-
18
  llm = ChatGroq(model="qwen-qwq-32b", temperature=0)
19
  chat_with_tools = llm.bind_tools(tools)
20
 
21
- def assistant(state: AgentState):
22
- table = state.get("wiki_table")
23
- context = []
24
-
25
- if table:
26
- context.append({"role": "system", "content": f"Here is a Wikipedia table you can use:\n\n{table}"})
27
-
28
  response = chat_with_tools.invoke(context + state["messages"])
29
  return {
30
- "messages": [response],
31
- "wiki_table": table,
32
  }
33
 
34
- def enhancer(state: AgentState):
35
  sys_msg = """You are a reasoning assistant that can answer complex questions using external tools. You must follow a structured reasoning format and always output a final answer.
36
  Always follow this step-by-step structure:
37
 
@@ -50,12 +38,11 @@ def build_agent():
50
  - If a comma-separated list: apply the above rules to each element.
51
  - Only include the final answer, do not include any reasoning steps."""
52
  return {
53
- "messages": [{"role": "system", "content": sys_msg}] + state["messages"],
54
- "wiki_table": None
55
  }
56
 
57
  ## The graph
58
- builder = StateGraph(AgentState)
59
 
60
  # Define nodes: these do the work
61
  builder.add_node("enhancer", enhancer)
 
10
  tools = [add, multiply, divide, subtract, search_wikipedia]
11
 
12
  def build_agent():
 
 
 
 
 
13
  llm = ChatGroq(model="qwen-qwq-32b", temperature=0)
14
  chat_with_tools = llm.bind_tools(tools)
15
 
16
+ def assistant(state: MessagesState):
 
 
 
 
 
 
17
  response = chat_with_tools.invoke(context + state["messages"])
18
  return {
19
+ "messages": [response]
 
20
  }
21
 
22
+ def enhancer(state: MessagesState):
23
  sys_msg = """You are a reasoning assistant that can answer complex questions using external tools. You must follow a structured reasoning format and always output a final answer.
24
  Always follow this step-by-step structure:
25
 
 
38
  - If a comma-separated list: apply the above rules to each element.
39
  - Only include the final answer, do not include any reasoning steps."""
40
  return {
41
+ "messages": [{"role": "system", "content": sys_msg}] + state["messages"]
 
42
  }
43
 
44
  ## The graph
45
+ builder = StateGraph(MessagesState)
46
 
47
  # Define nodes: these do the work
48
  builder.add_node("enhancer", enhancer)