-
Notifications
You must be signed in to change notification settings - Fork 4k
Python: Concept of self-hosted agent #10624
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
Conversation
python/samples/concepts/agents/self_hosted_agent/app/self_hosted_api_chat_completion.py
Outdated
Show resolved
Hide resolved
74777f2
to
adec526
Compare
python/samples/concepts/agents/self_hosted_agent/app/self_hosted_api_chat_completion.py
Outdated
Show resolved
Hide resolved
python/samples/concepts/agents/self_hosted_agent/app/self_hosted_api_chat_completion.py
Outdated
Show resolved
Hide resolved
python/samples/demos/self_hosted_agent/app/self_hosted_api_chat_completion.py
Show resolved
Hide resolved
Co-authored-by: Eduard van Valkenburg <eavanvalkenburg@users.noreply.github.com>
Co-authored-by: Eduard van Valkenburg <eavanvalkenburg@users.noreply.github.com>
@eavanvalkenburg bumping it up for your review |
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.
couple of small notes
""" | ||
|
||
|
||
class APIRequestFormat(BaseModel, ABC): |
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.
why is this a ABC?
messages = request.messages | ||
logger.info("Financial Coach agent") | ||
logger.info(messages) | ||
openai = await client.inference.get_azure_openai_client(api_version="2024-06-01") |
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.
I would prefer to see SK used for these agents as well, and maybe even different types of agents... CC: @moonbox3
|
||
agent_reviewer = ChatCompletionAgent( | ||
id="artdirector", | ||
kernel=kernel, |
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.
no need to add a kernel anymore
|
||
agent_writer = ChatCompletionAgent( | ||
id="copywriter", | ||
kernel=kernel, |
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.
same
So sorry for the delay on this. Will have a look tomorrow. |
I want to chat with the team a bit more around this new idea. We're going to be introducing some new orchestration patterns for agents soon, and I want to make sure that things will align properly. |
self._handle_structured_output(settings, settings_dict) | ||
if settings.tools is None: | ||
settings_dict.pop("parallel_tool_calls", None) | ||
async with httpx.AsyncClient(timeout=30) as client: |
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.
One can already pass in a custom client and service:
from httpx import AsyncClient
async with AsyncClient(timeout=30) as http_client:
custom_openai_client = AsyncOpenAI(http_client=http_client)
custom_openai_service = OpenAIChatCompletion(async_client=custom_openai_client)
agent = ChatCompletionAgent(
service=custom_openai_service,
name="Host",
instructions="Answer questions about the menu.",
)
By doing so, one can leverage the existing code in the OpenAIChatCompletionBase
I think it's okay if you want to show a demo using custom httpx.AsyncClient, but I don't think that requires the need to re-write a class when you can already pass in that custom httpx client and it will be used as part of the Please update to simplify the demo/code, and re-open the PR if you choose to move forward with it. Thank you. |
Motivation and Context
In the agentic world, different agents are created and maintained by different teams in an organization. Each team has their own way of creating agents and hosting them which are independent of each other. To utilize these agents when creating a multi-agent application, semantic kernel will need to integrate with agents which lies outside the semantic kernel application. For semantic kernel, these agents are black box services that have their own implementation of "intelligence" but could still use the plugins registered in kernel as needed.
AgentGroupChat
should be able to orchestrate between these agents as usual.Description
Although there could be multiple ways to implement such concept, this PR takes the approach of deriving from
ChatCompletionClientBase
and taking inspiration fromOpenAIChatCompletionBase
to implementSelfHostedChatCompletion
which makes a REST request to externally hosted agents. Instances ofSelfHostedChatCompletion
are registered as service in kernelChatCompletionAgent
is used to create agents and the appropriate service is referenced usingservice_id
.The agents themselves are implemented in a fastapi server under
agents
folder.AgentGroupChat
is used to orchestrate between the agents.Contribution Checklist