-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Python: Test #5344
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
Closed
Tao Chen (TaoChenOSU)
wants to merge
11
commits into
main
from
feature/python-foundry-hosted-agent-vnext
Closed
Python: Test #5344
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
615ef90
Python: Wrapper + Samples 1st (#5177)
TaoChenOSU a98a585
Update dependency (#5215)
TaoChenOSU 9ce2aaf
Add tests and more content types (#5235)
TaoChenOSU 448f46a
Merge branch 'main' into feature/python-foundry-hosted-agent-vnext
TaoChenOSU 0402b1a
Merge branch 'main' into feature/python-foundry-hosted-agent-vnext
TaoChenOSU 383a2af
Python: Refine samples and upgrade packages (#5261)
TaoChenOSU 9e3983e
Move samples (#5281)
TaoChenOSU 3225a59
Python: Upgrade agentserver packages (#5284)
TaoChenOSU 892d88d
Merge branch 'main' into feature/python-foundry-hosted-agent-vnext
TaoChenOSU 55e0705
Merge branch 'main' into feature/python-foundry-hosted-agent-vnext
TaoChenOSU 0fcd71d
Python: Add special handling for workflows (#5298)
TaoChenOSU File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| ], | ||
| "words": [ | ||
| "aeiou", | ||
| "agentserver", | ||
| "agui", | ||
| "aiplatform", | ||
| "azuredocindex", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
13 changes: 13 additions & 0 deletions
13
python/packages/foundry_hosting/agent_framework_foundry_hosting/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] |
75 changes: 75 additions & 0 deletions
75
python/packages/foundry_hosting/agent_framework_foundry_hosting/_invocations.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
TaoChenOSU marked this conversation as resolved.
|
||
|
|
||
|
|
||
| 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: | ||
| """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"}, | ||
| ) | ||
|
|
||
| response = await self._agent.run([user_message], session=session, stream=stream) | ||
| return JSONResponse({ | ||
| "response": response.text, | ||
| "session_id": session_id, | ||
| }) | ||
|
TaoChenOSU marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.