Skip to content

Commit c49ce53

Browse files
Address PR review: rename files, fix placement, add session usage, remove note
Co-authored-by: eavanvalkenburg <[email protected]>
1 parent d9513cc commit c49ce53

6 files changed

Lines changed: 26 additions & 23 deletions

File tree

‎python/samples/02-agents/context_providers/redis/redis_conversation.py‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
This example demonstrates how to use the Redis context provider to persist
66
conversational details. Pass it as a constructor argument to create_agent.
77
8+
Note: For session history persistence, see RedisHistoryProvider in the
9+
conversations/redis_history_provider.py sample. RedisContextProvider is for
10+
AI context (RAG, memories), while RedisHistoryProvider stores message history.
11+
812
Requirements:
913
- A Redis instance with RediSearch enabled (e.g., Redis Stack)
1014
- agent-framework with the Redis extra installed: pip install "agent-framework-redis"
@@ -17,6 +21,7 @@
1721
import asyncio
1822
import os
1923

24+
from agent_framework import AgentSession
2025
from agent_framework.azure import AzureOpenAIResponsesClient
2126
from agent_framework.redis import RedisContextProvider
2227
from azure.identity import AzureCliCredential
@@ -77,35 +82,38 @@ async def main() -> None:
7782
context_providers=[provider],
7883
)
7984

85+
# Create a session to manage conversation state
86+
session = agent.create_session()
87+
8088
# Teach a user preference; the agent writes this to the provider's memory
8189
query = "Remember that I enjoy gumbo"
82-
result = await agent.run(query)
90+
result = await agent.run(query, session=session)
8391
print("User: ", query)
8492
print("Agent: ", result)
8593

8694
# Ask the agent to recall the stored preference; it should retrieve from memory
8795
query = "What do I enjoy?"
88-
result = await agent.run(query)
96+
result = await agent.run(query, session=session)
8997
print("User: ", query)
9098
print("Agent: ", result)
9199

92100
query = "What did I say to you just now?"
93-
result = await agent.run(query)
101+
result = await agent.run(query, session=session)
94102
print("User: ", query)
95103
print("Agent: ", result)
96104

97105
query = "Remember that I have a meeting at 3pm tomorro"
98-
result = await agent.run(query)
106+
result = await agent.run(query, session=session)
99107
print("User: ", query)
100108
print("Agent: ", result)
101109

102110
query = "Tulips are red"
103-
result = await agent.run(query)
111+
result = await agent.run(query, session=session)
104112
print("User: ", query)
105113
print("Agent: ", result)
106114

107115
query = "What was the first thing I said to you this conversation?"
108-
result = await agent.run(query)
116+
result = await agent.run(query, session=session)
109117
print("User: ", query)
110118
print("Agent: ", result)
111119
# Drop / delete the provider index in Redis

python/samples/02-agents/conversations/custom_chat_message_store_session.py renamed to python/samples/02-agents/conversations/custom_history_provider.py

File renamed without changes.

python/samples/02-agents/conversations/redis_chat_message_store_session.py renamed to python/samples/02-agents/conversations/redis_history_provider.py

File renamed without changes.

‎python/samples/02-agents/providers/anthropic/anthropic_skills.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from agent_framework.anthropic import AnthropicChatOptions, AnthropicClient
99
from dotenv import load_dotenv
1010

11+
# Load environment variables from .env file
12+
load_dotenv()
13+
1114
logger = logging.getLogger(__name__)
1215
"""
1316
Anthropic Skills Agent Example
@@ -20,9 +23,6 @@
2023
- Catching and downloading generated files from the agent.
2124
"""
2225

23-
# Load environment variables from .env file
24-
load_dotenv()
25-
2626

2727
async def main() -> None:
2828
"""Example of streaming response (get results as they are generated)."""

‎python/samples/02-agents/providers/openai/openai_responses_client_with_hosted_mcp.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
from agent_framework.openai import OpenAIResponsesClient
88
from dotenv import load_dotenv
99

10+
if TYPE_CHECKING:
11+
from agent_framework import AgentSession, SupportsAgentRun
12+
13+
# Load environment variables from .env file
14+
load_dotenv()
15+
1016
"""
1117
OpenAI Responses Client with Hosted MCP Example
1218
@@ -15,13 +21,6 @@
1521
"""
1622

1723

18-
if TYPE_CHECKING:
19-
from agent_framework import AgentSession, SupportsAgentRun
20-
21-
# Load environment variables from .env file
22-
load_dotenv()
23-
24-
2524
async def handle_approvals_without_session(query: str, agent: "SupportsAgentRun"):
2625
"""When we don't have a session, we need to ensure we return with the input, approval request and approval."""
2726
from agent_framework import Message

‎python/samples/03-workflows/checkpoint/checkpoint_with_human_in_the_loop.py‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
from pathlib import Path
99
from typing import Any
1010

11-
# NOTE: the Azure client imports above are real dependencies. When running this
12-
# sample outside of Azure-enabled environments you may wish to swap in the
13-
# `agent_framework.builtin` chat client or mock the writer executor. We keep the
14-
# concrete import here so readers can see an end-to-end configuration.
1511
from agent_framework import (
1612
AgentExecutor,
1713
AgentExecutorRequest,
@@ -34,6 +30,9 @@
3430
else:
3531
from typing_extensions import override # type: ignore[import] # pragma: no cover
3632

33+
# Load environment variables from .env file
34+
load_dotenv()
35+
3736
"""
3837
Sample: Checkpoint + human-in-the-loop quickstart.
3938
@@ -61,9 +60,6 @@
6160
re-emit the same ``.
6261
"""
6362

64-
# Load environment variables from .env file
65-
load_dotenv()
66-
6763
# Directory used for the sample's temporary checkpoint files. We isolate the
6864
# demo artefacts so that repeated runs do not collide with other samples and so
6965
# the clean-up step at the end of the script can simply delete the directory.

0 commit comments

Comments
 (0)