-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent_with_callback.py
63 lines (50 loc) · 2.1 KB
/
agent_with_callback.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Demo of simple Python code production Agent with an Evaluator Agent as a callback
Sean Browning
"""
import asyncio
import agents
import logging
import dotenv
# NOTE: This loads in env vars for openAI
dotenv.load_dotenv()
# Uncomment to see under the hood a bit more
# logger = logging.basicConfig(level=logging.INFO)
class DummyAgent(agents.Agent):
"""
A code producing agent with a simple prompt
"""
SYSTEM_PROMPT = "You are a language agent proficient in producing expressive and syntactically correct Python code."
BASE_PROMPT = "Write a simple program to fit an ordinary least squares regression model to a polars DataFrame input. Include a worked example in your response and provide only the code in code fences (ex. ```python)"
class DummyEvaluatorAgent(agents.Agent):
"""
An evaluator agent that will be called with the output of the above agent and give feedback on the response and the prompt
"""
SYSTEM_PROMPT = "You are a skilled project manager and evaluator of Python programs. You provide expert evaluation of whether code meets stated goals and reflect on how to improve the approach."
BASE_PROMPT = """
The following Python program was produced by an AI language agent:
{answer}
Here is the full history of the requested program and the response from the AI languge agent in response:
{scratchpad}
Reflect on the performance of the AI language model and provide feedback on how the initial prompt and resulting python code could be improved.
"""
if __name__ == "__main__":
# Run this with Interactive OAuth
prov = agents.AzureOpenAIProvider(
"gpt-4o-mini-nofilter",
interactive=True
)
ag = DummyAgent(
stopping_condition=agents.StopOnStep(1),
provider=prov,
callbacks=[
agents.AgentCallback(
DummyEvaluatorAgent,
provider=prov,
stopping_condition=agents.StopOnStep(1)
)
],
oai_kwargs={"temperature": 1.0}
)
asyncio.run(ag())
print(f"Answer:\n{ag.answer}\n\nFeedback:\n{ag.callback_output[0]}")