semantic-kernel
semantic-kernel copied to clipboard
Python: Concept of self-hosted agent
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 from OpenAIChatCompletionBase to implement SelfHostedChatCompletion which makes a REST request to externally hosted agents. Instances of SelfHostedChatCompletion are registered as service in kernel
kernel.add_service(
SelfHostedChatCompletion(
url=os.getenv("REVIEWER_AGENT_URL") or "", ai_model_id=REVIEWER_NAME, service_id=REVIEWER_NAME
)
)
ChatCompletionAgent is used to create agents and the appropriate service is referenced using service_id.
agent_reviewer = ChatCompletionAgent(
service_id="artdirector",
kernel=kernel,
name=REVIEWER_NAME,
arguments=KernelArguments(settings=PromptExecutionSettings(service_id=REVIEWER_NAME)),
)
The agents themselves are implemented in a fastapi server under agents folder. AgentGroupChat is used to orchestrate between the agents.
Contribution Checklist
- [x] The code builds clean without any errors or warnings
- [x] The PR follows the SK Contribution Guidelines and the pre-submission formatting script raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone :smile:
@eavanvalkenburg bumping it up for your review
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.
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 OpenAIChatCompletionBase.
Please update to simplify the demo/code, and re-open the PR if you choose to move forward with it. Thank you.