Skip to content

Commit 99a0c2c

Browse files
committed
OpenAI Agents SDK example refined, bumped version to 0.2.0-alpha
1 parent 9abea43 commit 99a0c2c

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

examples/redis_assistant.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ async def build_agent():
1616
"run", "main.py"
1717
],
1818
"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"
2123
},
2224
}
2325
)
@@ -27,7 +29,7 @@ async def build_agent():
2729
# Create and return the agent
2830
agent = Agent(
2931
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",
3133
mcp_servers=[server]
3234
)
3335

@@ -45,16 +47,14 @@ async def cli(agent, max_history=30):
4547
break
4648

4749
if (len(q.strip()) > 0):
48-
# Add the user's message to history
49-
conversation_history.append({"role": "user", "content": q})
50-
5150
# Format the context into a single string
52-
context = ""
51+
history = ""
5352
for turn in conversation_history:
5453
prefix = "User" if turn["role"] == "user" else "Assistant"
55-
context += f"{prefix}: {turn['content']}\n"
54+
history += f"{prefix}: {turn['content']}\n"
5655

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)
5858

5959
response_text = ""
6060
async for event in result.stream_events():
@@ -63,7 +63,8 @@ async def cli(agent, max_history=30):
6363
response_text += event.data.delta
6464
print("\n")
6565

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})
6768
conversation_history.append({"role": "assistant", "content": response_text})
6869

6970

src/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.0-alpha"
1+
__version__ = "0.2.0-alpha"

0 commit comments

Comments
 (0)