Aurele000 commited on
Commit
88fc842
·
1 Parent(s): 64e044f

reflexion pour maths

Browse files
Files changed (2) hide show
  1. agent.py +54 -10
  2. requirements.txt +4 -1
agent.py CHANGED
@@ -15,7 +15,46 @@ llm_4o = ChatOpenAI(
15
  model_name="gpt-4o",
16
  openai_api_key=api_open_ai_agent_key, # ou variable d’environnement
17
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
 
19
 
20
  @tool
21
  def wiki_search(query: str) -> str:
@@ -112,22 +151,27 @@ web_search_openai_agent = create_react_agent(
112
  name="web_search_openai_agent",
113
  )
114
 
115
-
116
-
117
  math_agent = create_react_agent(
118
- model=llm_4o,
119
 
120
  tools=[add, multiply, divide],
121
  prompt=(
122
- "You are a math agent.\n\n"
123
  "INSTRUCTIONS:\n"
124
- "- Assist ONLY with math-related tasks\n"
125
- "- After you're done with your tasks, respond to the supervisor directly\n"
126
- "- Respond ONLY with the results of your work, do NOT include ANY other text."
127
- ),
128
- name="math_agent",
129
- )
 
 
 
 
 
 
130
 
 
131
 
132
  supervisor = create_supervisor(
133
  model=init_chat_model("openai:gpt-4o", api_key = api_open_ai_agent_key),
 
15
  model_name="gpt-4o",
16
  openai_api_key=api_open_ai_agent_key, # ou variable d’environnement
17
  )
18
+ llm_reasoning = ChatOpenAI(
19
+ model_name = "o3-2025-04-16",
20
+ openai_api_key=api_open_ai_agent_key, # ou variable d’environnement
21
+ )
22
+
23
+
24
+ llm_reasoning_small = ChatOpenAI(
25
+ model_name = "o4-mini-2025-04-16",
26
+ openai_api_key=api_open_ai_agent_key, # ou variable d’environnement
27
+ )
28
+
29
+ text_exemple = """
30
+ Set: {x, y, z}
31
+
32
+ Table:
33
+ * | x | y | z
34
+ --------------
35
+ x | x | y | z
36
+ y | y | x | x
37
+ z | z | x | y
38
+
39
+ → z * y = x, but y * z = x → equal
40
+ → y * z = x, but z * y = x → equal
41
+ → y * y = x, but y * y = x → equal
42
+ → All pairs commute → No counter-example
43
+
44
+ Answer: The operation is commutative.
45
+ """
46
+ exemple_2 = """
47
+ Table:
48
+ * | a | b
49
+ ------------
50
+ a | a | b
51
+ b | a | a
52
+
53
+ → a * b = b, but b * a = a ≠ b
54
+ → Counter-example: a, b
55
+ Answer: a, b
56
 
57
+ """
58
 
59
  @tool
60
  def wiki_search(query: str) -> str:
 
151
  name="web_search_openai_agent",
152
  )
153
 
 
 
154
  math_agent = create_react_agent(
155
+ model=llm_reasoning_small,
156
 
157
  tools=[add, multiply, divide],
158
  prompt=(
159
+ "You are a mathematical reasoning agent.\n\n"
160
  "INSTRUCTIONS:\n"
161
+ "- You are given mathematical structures such as sets, operations, and tables.\n"
162
+ "- You must analyze them for properties like commutativity, associativity, identity, etc.\n"
163
+ "- When given a Cayley table, check if x * y == y * x for all pairs to test commutativity.\n"
164
+ "- Return a precise answer, including any counter-example pairs if they exist.\n"
165
+ "- If a counter-example exists, return the set of involved elements in alphabetical order as a comma-separated list.\n"
166
+ "- Do not rely on numeric calculation only — work symbolically when needed.\n"
167
+ f"- Here are two examples : Example 1:{text_exemple}.\n"
168
+ f"Example 2:{exemple_2}."),
169
+
170
+
171
+
172
+
173
 
174
+ name="math_agent")
175
 
176
  supervisor = create_supervisor(
177
  model=init_chat_model("openai:gpt-4o", api_key = api_open_ai_agent_key),
requirements.txt CHANGED
@@ -4,4 +4,7 @@ langchain
4
  langgraph
5
  langchain-community
6
  langgraph-supervisor
7
- langchain-openai
 
 
 
 
4
  langgraph
5
  langchain-community
6
  langgraph-supervisor
7
+ langchain-openai
8
+ wikipedia
9
+ arxiv
10
+ pymupdf