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: ChatCompletionAgent constructor and invocation improvements #10604

Open
moonbox3 opened this issue Feb 19, 2025 · 3 comments
Open

Python: ChatCompletionAgent constructor and invocation improvements #10604

moonbox3 opened this issue Feb 19, 2025 · 3 comments
Assignees
Labels
agents python Pull requests for the Python Semantic Kernel

Comments

@moonbox3
Copy link
Contributor

Supporting the simplified agent scenario:

# necessary imports

async def main():
    agent = ChatCompletionAgent(
        service=OpenAIChatCompletion(),
        plugins=[DatePlugin(), WeatherPlugin()], #optional
        instructions="you are a helpful assistant that can answer questions about the world", #optional
    )

    print(await agent.invoke("What is the capital of France?"))

if __name__ == "__main__":
    asyncio.run(main())

as well as make updates for invoke: from AsyncIterable -> couroutine.

@moonbox3 moonbox3 added agents python Pull requests for the Python Semantic Kernel labels Feb 19, 2025
@moonbox3 moonbox3 self-assigned this Feb 19, 2025
@moonbox3 moonbox3 changed the title Python: agent "quality of life" updates Python: ChatCompletionAgent constructor and invocation improvements Feb 19, 2025
@eavanvalkenburg
Copy link
Member

Wouldn't you need Kernel as well in order to do the function calling and have things like Filters available as well?

# necessary imports

async def main():
    kernel.add_plugins([DatePlugin(), WeatherPlugin()])
    agent = ChatCompletionAgent(
        service=OpenAIChatCompletion(),
        kernel=kernel
        instructions="you are a helpful assistant that can answer questions about the world", #optional
    )

    print(await agent.invoke("What is the capital of France?"))

if __name__ == "__main__":
    asyncio.run(main())

@moonbox3
Copy link
Contributor Author

Today, if a kernel is not provided, we create one. So we'll use a model_validator after the model is formed, and add the plugins to the kernel for the caller. This is considered the "easiest" of easy paths where someone wants to write the most minimal amount of code to get started. We will still support that path where one can configure the kernel and pass it in, which you could say is the "medium/intermediate" path. Passing in plugins via the constructor will take precedence over any plugins added previously.

@eavanvalkenburg
Copy link
Member

gotcha, thanks for clarifying, that sounds good, less is more!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agents python Pull requests for the Python Semantic Kernel
Projects
Status: No status
Development

No branches or pull requests

2 participants