Python: Refine samples and upgrade packages (#5261)

* Refine samples and upgrade pacakges

* Upgrade to a new package that fixes a bug

* Update model env var
This commit is contained in:
Tao Chen
2026-04-15 10:46:19 -07:00
committed by GitHub
Unverified
parent 0402b1aac4
commit 383a2afca2
42 changed files with 285 additions and 517 deletions
@@ -17,7 +17,6 @@ class InvocationsHostServer(InvocationAgentServerHost):
self,
agent: BaseAgent,
*,
stream: bool = False,
openapi_spec: Optional[dict[str, Any]] = None,
**kwargs: Any,
) -> None:
@@ -25,7 +24,6 @@ class InvocationsHostServer(InvocationAgentServerHost):
Args:
agent: The agent to handle responses for.
stream: Whether to stream the responses. Defaults to True.
openapi_spec: The OpenAPI specification for the server.
**kwargs: Additional keyword arguments.
@@ -40,7 +38,6 @@ class InvocationsHostServer(InvocationAgentServerHost):
append_to_user_agent(self.USER_AGENT_PREFIX)
self._agent = agent
self._stream = stream
self._sessions: dict[str, AgentSession] = {}
self.invoke_handler(self._handle_invoke) # pyright: ignore[reportUnknownMemberType]
@@ -49,16 +46,17 @@ class InvocationsHostServer(InvocationAgentServerHost):
data = await request.json()
session_id: str = request.state.session_id
stream = data.get("stream", False)
user_message = data.get("message", None)
if user_message is None:
error = "Missing 'message' in request"
if self._stream:
if stream:
return StreamingResponse(content=error, status_code=400)
return Response(content=error, status_code=400)
session = self._sessions.setdefault(session_id, AgentSession(session_id=session_id))
if self._stream:
if stream:
async def stream_response() -> AsyncGenerator[str]:
async for update in self._agent.run(user_message, session=session, stream=True):
@@ -70,7 +68,7 @@ class InvocationsHostServer(InvocationAgentServerHost):
headers={"Cache-Control": "no-cache", "Connection": "keep-alive"},
)
response = await self._agent.run([user_message], session=session, stream=self._stream)
response = await self._agent.run([user_message], session=session, stream=stream)
return JSONResponse({
"response": response.text,
"session_id": session_id,
@@ -24,9 +24,9 @@ classifiers = [
]
dependencies = [
"agent-framework-core>=1.0.0,<2",
"azure-ai-agentserver-core==2.0.0a20260410006",
"azure-ai-agentserver-responses==1.0.0a20260410006",
"azure-ai-agentserver-invocations==1.0.0a20260410006",
"azure-ai-agentserver-core==2.0.0a20260414006",
"azure-ai-agentserver-responses==1.0.0a20260414006",
"azure-ai-agentserver-invocations==1.0.0a20260414006",
"azure-monitor-opentelemetry-exporter>=1.0.0a1"
]