@@ -16,8 +16,10 @@ async def build_agent():
16
16
"run" , "main.py"
17
17
],
18
18
"env" : {
19
- "REDIS_HOST" : "127.0.0.1" ,
20
- "REDIS_PORT" : "6379"
19
+ "REDIS_HOST" : "redis-18237.c1.us-east1-2.gce.cloud.redislabs.com" ,
20
+ "REDIS_PORT" : "18237" ,
21
+ "REDIS_USERNAME" : "mortensi" ,
22
+ "REDIS_PWD" : "RIi0j9*k4Oj6otnmGTPxvsGloDI7kjRP6"
21
23
},
22
24
}
23
25
)
@@ -27,7 +29,7 @@ async def build_agent():
27
29
# Create and return the agent
28
30
agent = Agent (
29
31
name = "Redis Assistant" ,
30
- instructions = "You are a helpful assistant capable of reading and writing to Redis." ,
32
+ instructions = "You are a helpful assistant capable of reading and writing to Redis. Store every question and answer in the Redis Stream app:logger " ,
31
33
mcp_servers = [server ]
32
34
)
33
35
@@ -45,16 +47,14 @@ async def cli(agent, max_history=30):
45
47
break
46
48
47
49
if (len (q .strip ()) > 0 ):
48
- # Add the user's message to history
49
- conversation_history .append ({"role" : "user" , "content" : q })
50
-
51
50
# Format the context into a single string
52
- context = ""
51
+ history = ""
53
52
for turn in conversation_history :
54
53
prefix = "User" if turn ["role" ] == "user" else "Assistant"
55
- context += f"{ prefix } : { turn ['content' ]} \n "
54
+ history += f"{ prefix } : { turn ['content' ]} \n "
56
55
57
- result = Runner .run_streamed (agent , context .strip ())
56
+ context = f"Conversation history:/n{ history .strip ()} /n New question:/n{ q .strip ()} "
57
+ result = Runner .run_streamed (agent , context )
58
58
59
59
response_text = ""
60
60
async for event in result .stream_events ():
@@ -63,7 +63,8 @@ async def cli(agent, max_history=30):
63
63
response_text += event .data .delta
64
64
print ("\n " )
65
65
66
- # Store assistant's reply in history
66
+ # Add the user's message and the assistant's reply in history
67
+ conversation_history .append ({"role" : "user" , "content" : q })
67
68
conversation_history .append ({"role" : "assistant" , "content" : response_text })
68
69
69
70
0 commit comments