Wei Ren commited on
Commit
f6e10f4
·
1 Parent(s): 04e5a83

Fix: Remove invalid additional_prompting parameter

Browse files

- CodeAgent doesn't support additional_prompting parameter
- Instead, prepend optimization instructions to user message
- Instructs agent to execute code immediately without explanation
- Achieves same goal of skipping preliminary step

Files changed (1) hide show
  1. app.py +14 -19
app.py CHANGED
@@ -33,27 +33,12 @@ def create_agent():
33
  GetAdInsightsTool(),
34
  ]
35
 
36
- # Create the agent with optimized settings
37
  agent = CodeAgent(
38
  tools=tools,
39
  model=model,
40
  max_steps=10,
41
  verbosity_level=1,
42
- additional_prompting="""You are a Meta Ads assistant. When the user asks a question:
43
- 1. IMMEDIATELY write and execute code using the available tools
44
- 2. DO NOT explain what you will do first - just do it
45
- 3. Write code in the format: <code>tool_result = tool_name(params)</code>
46
- 4. After getting results, call final_answer() with the results
47
-
48
- Example:
49
- User: "Show me all my ad accounts"
50
- Your response should be:
51
- <code>
52
- accounts = get_ad_accounts()
53
- final_answer(accounts)
54
- </code>
55
-
56
- Be direct and efficient. Execute code immediately without preliminary explanations."""
57
  )
58
 
59
  return agent
@@ -73,9 +58,19 @@ def respond(
73
  # Create the agent
74
  agent = create_agent()
75
 
76
- # Run the agent directly with the user's message
77
- # The agent already has instructions in additional_prompting
78
- response = agent.run(message)
 
 
 
 
 
 
 
 
 
 
79
 
80
  yield str(response)
81
 
 
33
  GetAdInsightsTool(),
34
  ]
35
 
36
+ # Create the agent
37
  agent = CodeAgent(
38
  tools=tools,
39
  model=model,
40
  max_steps=10,
41
  verbosity_level=1,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  )
43
 
44
  return agent
 
58
  # Create the agent
59
  agent = create_agent()
60
 
61
+ # Add optimized instructions to make the agent execute code immediately
62
+ optimized_message = f"""Execute the following request immediately using the available tools. Do NOT explain what you will do - just write and execute the code directly.
63
+
64
+ User request: {message}
65
+
66
+ Instructions:
67
+ - Write code in <code> tags and execute it immediately
68
+ - Use the available tools: get_ad_accounts(), get_campaigns(), get_adsets(), get_ads(), get_ad_insights()
69
+ - After getting results, call final_answer() with the results
70
+ - Be direct and efficient"""
71
+
72
+ # Run the agent
73
+ response = agent.run(optimized_message)
74
 
75
  yield str(response)
76