Denis Davydov
commited on
Commit
·
c80da8b
1
Parent(s):
11d4518
fix redundant question context
Browse files
agent.py
CHANGED
|
@@ -73,9 +73,7 @@ def create_smart_agent():
|
|
| 73 |
)
|
| 74 |
builder.add_edge("tools", "assistant")
|
| 75 |
|
| 76 |
-
|
| 77 |
-
memory = MemorySaver()
|
| 78 |
-
agent = builder.compile(checkpointer=memory)
|
| 79 |
|
| 80 |
return agent
|
| 81 |
|
|
@@ -91,20 +89,15 @@ class SmartAgent:
|
|
| 91 |
try:
|
| 92 |
print(f"\n🎯 Processing question: {question[:100]}...")
|
| 93 |
|
| 94 |
-
# Create simple execution plan for logging
|
| 95 |
plan = create_execution_plan(question, task_id)
|
| 96 |
print(f"📋 Execution plan: {plan}")
|
| 97 |
|
| 98 |
-
# Prepare the question with task_id context if available
|
| 99 |
enhanced_question = question
|
| 100 |
if task_id:
|
| 101 |
-
enhanced_question = f"Task ID: {task_id}\n\nQuestion: {question}
|
| 102 |
|
| 103 |
-
# Invoke the agent - let GPT-4o decide what tools to use
|
| 104 |
-
thread_id = f"task-{task_id}" if task_id else "general"
|
| 105 |
config = {
|
| 106 |
-
"
|
| 107 |
-
"recursion_limit": 15 # Allow more tool usage for complex searches
|
| 108 |
}
|
| 109 |
|
| 110 |
initial_state = {
|
|
@@ -114,12 +107,10 @@ class SmartAgent:
|
|
| 114 |
|
| 115 |
result = self.agent.invoke(initial_state, config=config)
|
| 116 |
|
| 117 |
-
# Extract the final answer and reasoning trace
|
| 118 |
if result and 'messages' in result and result['messages']:
|
| 119 |
final_message = result['messages'][-1]
|
| 120 |
raw_answer = final_message.content
|
| 121 |
|
| 122 |
-
# Build reasoning trace from all messages
|
| 123 |
reasoning_trace = []
|
| 124 |
for msg in result['messages']:
|
| 125 |
if hasattr(msg, 'content') and msg.content:
|
|
|
|
| 73 |
)
|
| 74 |
builder.add_edge("tools", "assistant")
|
| 75 |
|
| 76 |
+
agent = builder.compile()
|
|
|
|
|
|
|
| 77 |
|
| 78 |
return agent
|
| 79 |
|
|
|
|
| 89 |
try:
|
| 90 |
print(f"\n🎯 Processing question: {question[:100]}...")
|
| 91 |
|
|
|
|
| 92 |
plan = create_execution_plan(question, task_id)
|
| 93 |
print(f"📋 Execution plan: {plan}")
|
| 94 |
|
|
|
|
| 95 |
enhanced_question = question
|
| 96 |
if task_id:
|
| 97 |
+
enhanced_question = f"Task ID: {task_id}\n\nQuestion: {question}"
|
| 98 |
|
|
|
|
|
|
|
| 99 |
config = {
|
| 100 |
+
"recursion_limit": 15
|
|
|
|
| 101 |
}
|
| 102 |
|
| 103 |
initial_state = {
|
|
|
|
| 107 |
|
| 108 |
result = self.agent.invoke(initial_state, config=config)
|
| 109 |
|
|
|
|
| 110 |
if result and 'messages' in result and result['messages']:
|
| 111 |
final_message = result['messages'][-1]
|
| 112 |
raw_answer = final_message.content
|
| 113 |
|
|
|
|
| 114 |
reasoning_trace = []
|
| 115 |
for msg in result['messages']:
|
| 116 |
if hasattr(msg, 'content') and msg.content:
|