-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathcall_server_af.py
More file actions
59 lines (42 loc) · 1.69 KB
/
Copy pathcall_server_af.py
File metadata and controls
59 lines (42 loc) · 1.69 KB
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
# Copyright (c) Microsoft. All rights reserved.
"""Agent Framework agent client for the local_responses sample.
Creates a local :class:`agent_framework.Agent` backed by
:class:`agent_framework.openai.OpenAIChatClient` and points that client at the
hosted ``/responses`` endpoint for all turns:
1. ``What is the weather in Tokyo?``
2. ``And what about Amsterdam?``
3. ``Which of the two cities we just discussed is warmer?``
All turns use the same :class:`agent_framework.AgentSession`; the first turn
binds the hosted response id to the session, and later turns continue through
that session via a chain of rotating ``previous_response_id`` values. The
third turn only makes sense if the server still remembers the first turn, so
it also exercises session continuity across that whole chain, not just a
single hop.
Start the server first (in another shell)::
uv run python app.py
Then::
uv run python call_server_af.py
"""
from __future__ import annotations
import asyncio
from agent_framework import Agent
from agent_framework.openai import OpenAIChatClient
BASE_URL = "http://127.0.0.1:8000"
PROMPTS = [
"What is the weather in Tokyo?",
"And what about Amsterdam?",
"Which of the two cities we just discussed is warmer?",
]
async def main() -> None:
agent = Agent(
client=OpenAIChatClient(base_url=BASE_URL, api_key="not-needed"),
name="HostedWeatherClient",
)
session = agent.create_session()
for prompt in PROMPTS:
print(f"User: {prompt}")
response = await agent.run(prompt, session=session)
print(f"Agent: {response.text}\n")
print(f"Response ID: {response.response_id}\n")
if __name__ == "__main__":
asyncio.run(main())