-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Python: Add more types #5377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: Add more types #5377
Changes from all commits
615ef90
a98a585
9ce2aaf
448f46a
0402b1a
383a2af
9e3983e
3225a59
892d88d
55e0705
0fcd71d
8bc7c3a
8b48604
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| ], | ||
| "words": [ | ||
| "aeiou", | ||
| "agentserver", | ||
| "agui", | ||
| "aiplatform", | ||
| "azuredocindex", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) Microsoft Corporation. | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Foundry Hosting | ||
|
|
||
| This package provides the integration of Agent Framework agents and workflows with the Foundry Agent Server, which can be hosted on Foundry infrastructure. | ||
|
|
||
| ## Responses | ||
|
|
||
| TODO | ||
|
|
||
| ## Invocations | ||
|
|
||
| TODO | ||
|
Comment on lines
+1
to
+11
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| import importlib.metadata | ||
|
|
||
| from ._invocations import InvocationsHostServer | ||
| from ._responses import ResponsesHostServer | ||
|
|
||
| try: | ||
| __version__ = importlib.metadata.version(__name__) | ||
| except importlib.metadata.PackageNotFoundError: | ||
| __version__ = "0.0.0" | ||
|
|
||
| __all__ = ["InvocationsHostServer", "ResponsesHostServer"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| from agent_framework import AgentSession, BaseAgent, SupportsAgentRun | ||
| from agent_framework._telemetry import append_to_user_agent | ||
| from azure.ai.agentserver.invocations import InvocationAgentServerHost | ||
| from starlette.requests import Request | ||
| from starlette.responses import JSONResponse, Response, StreamingResponse | ||
| from typing_extensions import Any, AsyncGenerator, Optional | ||
|
|
||
|
|
||
| class InvocationsHostServer(InvocationAgentServerHost): | ||
| """An invocations server host for an agent.""" | ||
|
|
||
| USER_AGENT_PREFIX = "foundry-hosting" | ||
|
|
||
| def __init__( | ||
| self, | ||
| agent: BaseAgent, | ||
| *, | ||
| openapi_spec: Optional[dict[str, Any]] = None, | ||
| **kwargs: Any, | ||
| ) -> None: | ||
|
Comment on lines
+16
to
+22
|
||
| """Initialize an InvocationsHostServer. | ||
|
|
||
| Args: | ||
| agent: The agent to handle responses for. | ||
| openapi_spec: The OpenAPI specification for the server. | ||
| **kwargs: Additional keyword arguments. | ||
|
|
||
| This host will expect the request to be a JSON body with a "message" field. | ||
| The response from the host will be a JSON object with a "response" field containing | ||
| the agent's response and a "session_id" field containing the session ID. | ||
| """ | ||
| super().__init__(openapi_spec=openapi_spec, **kwargs) | ||
|
|
||
| if not isinstance(agent, SupportsAgentRun): | ||
| raise TypeError("Agent must support the SupportsAgentRun interface") | ||
|
|
||
| append_to_user_agent(self.USER_AGENT_PREFIX) | ||
| self._agent = agent | ||
| self._sessions: dict[str, AgentSession] = {} | ||
| self.invoke_handler(self._handle_invoke) # pyright: ignore[reportUnknownMemberType] | ||
|
|
||
| async def _handle_invoke(self, request: Request) -> Response: | ||
| """Invoke the agent with the given request.""" | ||
| 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 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 stream: | ||
|
|
||
| async def stream_response() -> AsyncGenerator[str]: | ||
| async for update in self._agent.run(user_message, session=session, stream=True): | ||
| yield update.text | ||
|
|
||
| return StreamingResponse( | ||
| stream_response(), | ||
| media_type="text/event-stream", | ||
| headers={"Cache-Control": "no-cache", "Connection": "keep-alive"}, | ||
| ) | ||
|
Comment on lines
+59
to
+69
|
||
|
|
||
| response = await self._agent.run([user_message], session=session, stream=stream) | ||
| return JSONResponse({ | ||
| "response": response.text, | ||
| "session_id": session_id, | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
append_to_user_agentdocstring says it prepends the prefix, but the implementation appends to_user_agent_prefixes, which means later prefixes appear after earlier ones in the final User-Agent. Either update the docstring to say "append"/"add" (and describe ordering), or change the implementation to insert at the front so the behavior matches the docstring.