Skip to content

Aegis structure message #6289

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

Merged
merged 23 commits into from
Apr 16, 2025
Merged

Conversation

abhinav-aegis
Copy link
Contributor

Why are these changes needed?

Related issue number

Checks

Added support for structured message component using the Json to Pydantic utility functions. Note: also adding the ability to use a format string for structured messages.

abhinav-aegis and others added 10 commits April 9, 2025 00:59
…icrosoft#6260)

<!-- 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?

`IncludeEnum` was removed in ChromaDB when it was updated to `1.0.0`.
This caused issues when using `ChromaDBVectorMemory`. This PR fixes
those issues

## Related issue number

Closes microsoft#6241

## Checks

- [x] 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.
- [x] I've made sure all auto checks have passed.

---------

Co-authored-by: Victor Dibia <[email protected]>
Closes microsoft#6265

Convert the `Message` and `Resource` dataclasses to Pydantic models in
the `llamaindex-agent` cookbook.

* Replace `dataclass` with `BaseModel` for `Message` and `Resource`
classes.
* Update imports to use `BaseModel` from `pydantic`

Co-authored-by: Victor Dibia <[email protected]>
<!-- 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. -->

## Related issue number

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

## Checks

- [x] 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.
- [x] I've made sure all auto checks have passed.

Signed-off-by: zhanluxianshen <[email protected]>
Co-authored-by: Victor Dibia <[email protected]>
<!-- 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. -->

An app can pass untyped dicts to set configuration options of various
Task-Centric Memory classes. But tools like pyright can complain about
the loose typing. This PR exposes 4 TypedDict classes that apps can
optionally use.

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

## Related issue number

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

## Checks

- [x] 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.
adding email agent

## Why are these changes needed?

This PR introduces an AI-powered email assistant that can generate
images, attach files, draft reports, and send emails to multiple
recipients or specific users based on their queries. This feature is
highly beneficial for customer management and email marketing, enhancing
automation and improving efficiency.

## Related issue number

Open microsoft#6228 
## Checks

- [x] 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.
- [x] I've made sure all auto checks have passed.
@ekzhu ekzhu self-requested a review April 13, 2025 03:40
@ekzhu ekzhu assigned jackgerrits and unassigned jackgerrits Apr 13, 2025
@abhinav-aegis
Copy link
Contributor Author

The StructuredMessageFactory code is largely hidden from the User and is taken care of automatically in the background. So this code below works out of the box with the user not being aware of how the StructuredMessageComponent is being serialized and deserialized in the background. Notice how in the code below we can run the dump_component/load_component and it seems to work fine for me:

from pydantic import BaseModel, ValidationError
from typing import Literal

from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.base import TaskResult
from autogen_agentchat.conditions import TextMentionTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import OpenAIChatCompletionClient

# Create an OpenAI model client.
model_client = OpenAIChatCompletionClient(
    model="gpt-4o-2024-08-06",
)

class Critique(BaseModel):
    score: int
    review: str
    approved: Literal["APPROVE", "REJECT"]

# Create the primary agent.
primary_agent = AssistantAgent(
    "primary",
    model_client=model_client,
    system_message="You are a helpful AI assistant.",
)
format_string = "Score: {score}/10\nReview: {review},\n Approved: {approved}"

# Create the critic agent.
critic_agent = AssistantAgent(
    "critic",
    model_client=model_client,
    system_message="Provide constructive feedback with a score, review and approved or not in json fromat. Respond with approved:"APPROVED" when your feedbacks are addressed.",
    output_content_type=Critique,
    format_string=format_string,
)

# Define a termination condition that stops the task if the critic approves.
text_termination = TextMentionTermination("APPROVE")

# Create a team with the primary and critic agents.
team = RoundRobinGroupChat([primary_agent, critic_agent], termination_condition=text_termination, max_turns=10)

config = team.dump_component()
loaded_team = RoundRobinGroupChat.load_component(config)

async def main() -> None:
    await Console(loaded_team.run_stream(task="tell me a poem"))

Copy link
Collaborator

@ekzhu ekzhu left a comment

Choose a reason for hiding this comment

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

Looks great! I think we still need to fix various CI errors.

You may need to change your local uv version to 0.5.18.

uv self update 0.5.18

And then run uv sync --all-extras to fix the uv.lock file or revert it to the main version.

Copy link

codecov bot commented Apr 16, 2025

Codecov Report

Attention: Patch coverage is 90.80000% with 23 lines in your changes missing coverage. Please review.

Project coverage is 77.48%. Comparing base (8bd162f) to head (2d3f83b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...n-core/src/autogen_core/utils/_json_to_pydantic.py 89.84% 20 Missing ⚠️
...en_agentchat/teams/_group_chat/_base_group_chat.py 71.42% 2 Missing ⚠️
...utogen-agentchat/src/autogen_agentchat/messages.py 96.87% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6289      +/-   ##
==========================================
+ Coverage   77.24%   77.48%   +0.23%     
==========================================
  Files         200      202       +2     
  Lines       14473    14717     +244     
==========================================
+ Hits        11180    11403     +223     
- Misses       3293     3314      +21     
Flag Coverage Δ
unittests 77.48% <90.80%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ekzhu ekzhu merged commit a4a16fd into microsoft:main Apr 16, 2025
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants