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

Document structured output for for AssistantAgent in its API doc, and note strict=True is required for FunctionTool #5562

Closed
chengyu-liu-cs opened this issue Feb 15, 2025 · 8 comments · Fixed by #5653
Assignees
Labels
documentation Improvements or additions to documentation proj-agentchat
Milestone

Comments

@chengyu-liu-cs
Copy link

chengyu-liu-cs commented Feb 15, 2025

What feature would you like to be added?

Current AssistantAgent does not support response_format for structured output.
extra_create_args={ "response_format": "Pydantic model", }
It would be perfect if respose_format can be supported by both on_messages and on_messages_stream.

Why is this needed?

It is a good feature supported by many models to return structured output. It would simplify integration with other application in cases where predefined structures are expected from AssistantAgent.

It seems it is supported by OpenAIChatCompletionClient

@ekzhu
Copy link
Collaborator

ekzhu commented Feb 15, 2025

You can pass the client with structured output into the agent, which will then generate structured output: https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/tutorial/agents.html#structured-output

Make sure your FunctionTool is set to strict=True when using this.

@ekzhu ekzhu added this to the 0.4.7-python milestone Feb 15, 2025
@ekzhu ekzhu changed the title response_format parameter support for AssistantAgent Document structured output for for AssistantAgent in its API doc, and note strict=True is required for FunctionTool Feb 15, 2025
@ekzhu ekzhu added documentation Improvements or additions to documentation proj-agentchat labels Feb 15, 2025
@ekzhu ekzhu modified the milestones: 0.4.7-python, python-v0.4.8 Feb 15, 2025
@chengyu-liu-cs
Copy link
Author

@ekzhu , It would be different right if the response_format is configured at client and create levels. If it sets in client level, all the create will generate the structured outputs. While configuring at create level should provide much better flexibility.

For example, if a user says "hello", then the output should be just "hello" instead of enforcing structured outputs.

@chengyu-liu-cs
Copy link
Author

chengyu-liu-cs commented Feb 16, 2025

@ekzhu ,
I was testing the example in the link you provided. Instead of testing the example as it is, I was testing with model_client_stream=True,. There was an error below. Is this something AutoGen will work on ? Is it possible to stream in this scenario, and is there workaround ?
It seems from OpenAI side this is possible

"""
autogen/lib/python3.10/site-packages/openai/resources/chat/completions.py", line 1786, in validate_response_format raise TypeError( TypeError: You tried to pass a BaseModelclass tochat.completions.create(); You must use beta.chat.completions.parse() instead
"""

@ekzhu
Copy link
Collaborator

ekzhu commented Feb 16, 2025

This is indeed a bug in the model client. Can you create a separate issue for this?

Open AI's client uses a different api for structure output. I think the create_stream method has not been updated to use it.

@ekzhu
Copy link
Collaborator

ekzhu commented Feb 16, 2025

@ekzhu , It would be different right if the response_format is configured at client and create levels. If it sets in client level, all the create will generate the structured outputs. While configuring at create level should provide much better flexibility.

For example, if a user says "hello", then the output should be just "hello" instead of enforcing structured outputs.

How does one know when to use structured outputs and when not to? The model cannot decide this. When you pass in a base model in the response format in create method, it will still enforce the structure output. So it becomes the same thing as passing response format in the client which gets passed into the agent.

Perhaps some dynamic approach to detect user intent and then decide whether to use structured output is possible. However, the AssistantAgent is already quite complex and if we add more complex behaviour it will become confusing.

@chengyu-liu-cs
Copy link
Author

Perhaps some dynamic approach to detect user intent and then decide whether to use structured output is possible. However, the AssistantAgent is already quite complex and if we add more complex behaviour it will become confusing.

Exactly. First, detect intents and then dynamically decide if tools and response_format should be attached in model calls.

Any tips or example implementations if this would not be included in AssistantAgent ?

@chengyu-liu-cs
Copy link
Author

This is indeed a bug in the model client. Can you create a separate issue for this?

Open AI's client uses a different api for structure output. I think the create_stream method has not been updated to use it.

Yes. I will create a new issue for this.

@ekzhu
Copy link
Collaborator

ekzhu commented Feb 18, 2025

Any tips or example implementations if this would not be included in AssistantAgent ?

I think this can be a great idea for a custom agent that is meant to be a multi-purpose agent. Or, perhaps a selector group chat with dynamic routing based on user's intent.

@ekzhu ekzhu self-assigned this Feb 22, 2025
kadenbking added a commit to kadenbking/autogen that referenced this issue Feb 25, 2025
* doc: Enrich AssistantAgent API documentation with usage examples. (microsoft#5653)

Resolves microsoft#5562

* remove dep on aspire - add google.protobuf (microsoft#5645)

<!-- Thank you for your contribution! Please review
https://microsoft.github.io/autogen/docs/Contribute before opening a
pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

<!-- Please give a short summary of the change and the problem this
solves. -->

removes unneeded deps

## Related issue number

<!-- For example: "Closes microsoft#1234" -->

Closes microsoft#5644

## Checks

- [ ] I've included any doc changes needed for
<https://microsoft.github.io/autogen/>. See
<https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to
build and test documentation locally.
- [ ] I've added tests (if relevant) corresponding to the changes
introduced in this PR.
- [ ] I've made sure all auto checks have passed.

* [dotnet] Add mixin for easier state save/load apis (microsoft#5438)

Co-authored-by: Ryan Sweet <[email protected]>

* Replace the undefined tools variable with tool_schema parameter in ToolUseAgent class (microsoft#5684)

Replace the undefined `tools` variable with `tool_schema` parameter

<!-- Thank you for your contribution! Please review
https://microsoft.github.io/autogen/docs/Contribute before opening a
pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?
This change keeps the documentation up to date :
https://microsoft.github.io/autogen/stable//user-guide/core-user-guide/components/tools.html

<!-- Please give a short summary of the change and the problem this
solves. -->

## Related issue number

<!-- For example: "Closes microsoft#1234" -->

## Checks

- [ ] I've included any doc changes needed for
<https://microsoft.github.io/autogen/>. See
<https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to
build and test documentation locally.
- [x] I've added tests (if relevant) corresponding to the changes
introduced in this PR.
- [ ] I've made sure all auto checks have passed.

* Improve readme inconsistency (microsoft#5691)

### Before

<img width="823" alt="image"
src="https://github.com/user-attachments/assets/d5ba1671-9433-4fa4-9884-c0de6fafb82e"
/>



### After
<img width="803" alt="image"
src="https://github.com/user-attachments/assets/07fdd32a-d2ad-450d-8b7f-b21f10f14c85"
/>

* pack agenthost as tool (microsoft#5647)

<!-- Thank you for your contribution! Please review
https://microsoft.github.io/autogen/docs/Contribute before opening a
pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

convenience - allows to just run "agenthost"

```
dotnet pack --no-build --configuration Release --output './output/release' -bl\n
dotnet tool install --add-source ./output/release Microsoft.AutoGen.AgentHost
agenthost 
```

<!-- Please give a short summary of the change and the problem this
solves. -->

## Related issue number

<!-- For example: "Closes microsoft#1234" -->

closes microsoft#5646 

## Checks

- [ ] I've included any doc changes needed for
<https://microsoft.github.io/autogen/>. See
<https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to
build and test documentation locally.
- [ ] I've added tests (if relevant) corresponding to the changes
introduced in this PR.
- [ ] I've made sure all auto checks have passed.

* update versions to 0.4.8 (microsoft#5689)

* Update issue templates (microsoft#5686)

* doc & sample: Update documentation for human-in-the-loop and UserProxyAgent; Add UserProxyAgent to ChainLit sample; (microsoft#5656)

Resolves microsoft#5610

And address various questions regarding to how to use user proxy agent
and human-in-the-loop.

* doc: Update SelectorGroupChat doc on how to use O3-mini model. (microsoft#5657)

Resolves microsoft#5408

Co-authored-by: Jack Gerrits <[email protected]>

* Add metadata field to basemessage (microsoft#5372)

Add metadata field to BaseMessage.

Why?
- additional metadata field can track 1) timestamp if needed, 2) flags
about the message. For instance, a use case is a metadata field
{"internal":"yes"} that would hide messages from being displayed in an
application or studio.

As long as an extra field is added to basemessage that is not consumed
by existing agents, I am happy.



Notes:
- We can also only add it to BaseChatMessage, that would be fine
- I don't care what the extra field is called as long as there is an
extra field somewhere
- I don't have preference for the type, a str could work, but a dict
would be more useful.

---------

Co-authored-by: Eric Zhu <[email protected]>

* Change base image to one with arm64 support (microsoft#5681)

---------

Co-authored-by: Eric Zhu <[email protected]>
Co-authored-by: Ryan Sweet <[email protected]>
Co-authored-by: Jack Gerrits <[email protected]>
Co-authored-by: Shubham Shukla <[email protected]>
Co-authored-by: gagb <[email protected]>
Co-authored-by: Hussein Mozannar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation proj-agentchat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants