@@ -51,6 +51,90 @@ def get_weather(
5151 print (f" -> { result .text [:60 ]} " )
5252
5353
54+ async def run_tool_call ():
55+ """Scenario: Agent Framework chat client tool calling with native telemetry."""
56+ from agent_framework import Message , tool
57+ from agent_framework .observability import enable_sensitive_telemetry
58+ from agent_framework .openai import OpenAIChatCompletionClient
59+
60+ print (" [chat_tool_call] chat client with tool calling (native telemetry)" )
61+
62+ enable_sensitive_telemetry (force = True )
63+
64+ @tool (approval_mode = "never_require" )
65+ def get_weather (
66+ location : Annotated [str , "The location to get the weather for." ],
67+ ) -> str :
68+ """Get the weather for a given location."""
69+ return f"Sunny in { location } "
70+
71+ client = OpenAIChatCompletionClient (
72+ model = "gpt-4o-mini" ,
73+ base_url = MOCK_BASE_URL ,
74+ api_key = "mock-key" ,
75+ )
76+ response = await client .get_response (
77+ [Message (role = "user" , contents = ["What's the weather in Seattle?" ])],
78+ options = {
79+ "tools" : [get_weather ],
80+ "temperature" : 0.2 ,
81+ "top_p" : 0.9 ,
82+ "max_tokens" : 64 ,
83+ "seed" : 7 ,
84+ "stop" : ["<END>" ],
85+ "frequency_penalty" : 0.1 ,
86+ "presence_penalty" : 0.2 ,
87+ },
88+ )
89+ print (f" -> { response .text [:60 ]} " )
90+
91+
92+ async def run_chat_completion_agent_tool_call ():
93+ """Scenario: Agent Framework agent execution through Chat Completions."""
94+ from agent_framework import Agent , tool
95+ from agent_framework .observability import enable_sensitive_telemetry
96+ from agent_framework .openai import OpenAIChatCompletionClient
97+
98+ print (" [agent_chat_completion] agent with Chat Completions (native telemetry)" )
99+
100+ enable_sensitive_telemetry (force = True )
101+
102+ @tool (approval_mode = "never_require" )
103+ def get_weather (
104+ location : Annotated [str , "The location to get the weather for." ],
105+ ) -> str :
106+ """Get the weather for a given location."""
107+ return f"Sunny in { location } "
108+
109+ client = OpenAIChatCompletionClient (
110+ model = "gpt-4o-mini" ,
111+ base_url = MOCK_BASE_URL ,
112+ api_key = "mock-key" ,
113+ )
114+ agent = Agent (
115+ client = client ,
116+ id = "weather-agent-chat-completions" ,
117+ name = "WeatherAgentChatCompletions" ,
118+ description = "Answers weather questions with a function tool." ,
119+ instructions = "You are a helpful weather agent." ,
120+ tools = [get_weather ],
121+ )
122+
123+ result = await agent .run (
124+ "What's the weather in Seattle?" ,
125+ options = {
126+ "temperature" : 0.2 ,
127+ "top_p" : 0.9 ,
128+ "max_tokens" : 64 ,
129+ "seed" : 7 ,
130+ "stop" : ["<END>" ],
131+ "frequency_penalty" : 0.1 ,
132+ "presence_penalty" : 0.2 ,
133+ },
134+ )
135+ print (f" -> { result .text [:60 ]} " )
136+
137+
54138async def run_agent_workflow ():
55139 """Scenario: Agent Framework workflow execution with native telemetry."""
56140 from agent_framework import Agent , WorkflowBuilder
@@ -99,6 +183,8 @@ def main():
99183 tp , lp , mp = setup_otel ()
100184
101185 asyncio .run (run_agent_tool_call ())
186+ asyncio .run (run_tool_call ())
187+ asyncio .run (run_chat_completion_agent_tool_call ())
102188 asyncio .run (run_agent_workflow ())
103189
104190 flush_and_shutdown (tp , lp , mp )
0 commit comments