Skip to content
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: using agents as KernelFunctions #10828

Closed

Conversation

eavanvalkenburg
Copy link
Member

Motivation and Context

This adds a convenience method to allow a agent to be called by other agents or regular function calling.
Also includes some improvement in parsing of classes into KernelPlugins

Description

  • Adds a function to a Agent that uses the get_response and a single string 'Task' to run.
  • It takes the name and description of the agent for the function name and description and the task and output are annotated
  • Adds a sample showing how to have hierarchical agents calling each other.
  • Could be extended to also pass in chat_history, which currently doesn't happen.
  • Also adds some extra features to plugin creation and adding, now static methods in a class also get picked up, instead of just bound methods
  • Also checks if there is a attribute called 'name' and take that as the plugin_name if it exists.

Contribution Checklist

@eavanvalkenburg eavanvalkenburg requested a review from a team as a code owner March 6, 2025 10:09
@markwallace-microsoft markwallace-microsoft added the python Pull requests for the Python Semantic Kernel label Mar 6, 2025
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Mar 6, 2025

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
semantic_kernel/functions
   kernel_plugin.py181697%393, 396, 409, 434, 455, 480
TOTAL19619256187% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3211 5 💤 0 ❌ 0 🔥 1m 40s ⏱️

@TaoChenOSU
Copy link
Contributor

TaoChenOSU commented Mar 6, 2025

While I think it's ok to have agents as tools/plugins, I don't think that is a pattern we should encourage. We have the CrewAI as a plugin since it couldn't fit with our abstraction very well.

I am mainly concern about the following:

  1. Agents are supposedly used for long running tasks, and they may modify their environment. This may not fit well with the previous chat completion tasks, i.e. simple questions & answers.
  2. When should we advise people to invoke agents directly and when to use agents through kernel functions?
  3. I am not sure if passing an agent to another agent will be a pattern we will eventually have. It may be, but I think it is worth some more discussion. With the shared agent runtime that is in planning, we may end up doing this hierarchical pattern differently.

) -> Annotated[str, "The response from the agent."]:
history = ChatHistory()
history.add_user_message(task)
return (await self.get_response(history=history)).content
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not going to work with other types of agents except the chat completion agent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my info, why not? I saw get_response is a abstract method so should be available on every agent, or are the args different?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The args are different.

@eavanvalkenburg eavanvalkenburg marked this pull request as draft March 6, 2025 19:35
@moonbox3
Copy link
Contributor

Superseded by #11184.

@moonbox3 moonbox3 closed this Mar 25, 2025
github-merge-queue bot pushed a commit that referenced this pull request Mar 26, 2025
### Motivation and Context

We're moving towards a pattern where Agents can be called as tools. We
currently don't have this in Semantic Kernel Python.

This work builds off of the previous PR (#10828) but extends it to work
with any SK Agent now that we have a bit more of a common invocation
pattern (all agents take in `messages` kwarg). This also works now
because each agent creates its own thread internally, if one isn't
provided - so we don't need to worry about handling chat history for an
OpenAI Assistant or an Azure AI Agent.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Allow agents to be configured as Kernel Functions, which can then be
used during Function Calling. We will advertise the Agent's name and
either its description or instructions (if description is blank).
- Provide a sample where we show a triage agent (ChatCompletionAgent)
calling either a billing agent (ChatCompletionAgent) or a refund agent
(ChatCompletionAgent ) as part of a tool call to satisfy the user's
query.
- Provide a sample where we show a triage agent (ChatCompletionAgent)
calling either a billing agent (AzureAIAgent) or a refund agent
(ChatCompletionAgent) to satisfy the user's query.


<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests for the Python Semantic Kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants