Skip to content

Add AutoGen agent runner integration#306

Open
Bermpje wants to merge 12 commits intoopenagents-org:developfrom
Bermpje:feature/autogen-agent-runner
Open

Add AutoGen agent runner integration#306
Bermpje wants to merge 12 commits intoopenagents-org:developfrom
Bermpje:feature/autogen-agent-runner

Conversation

@Bermpje
Copy link
Copy Markdown
Contributor

@Bermpje Bermpje commented Mar 9, 2026

Closes #269

Summary

  • add AutoGenAgentRunner so AutoGen agents and teams can participate in OpenAgents networks
  • preserve OpenAgents tool schemas when converting to AutoGen tools and tighten the integration to documented AutoGen 0.7.5 behavior
  • add regression coverage for tool conversion, streaming, unsupported runtime injection, and package extras

What changed

  • added src/openagents/agents/autogen_agent.py with:
    • AutoGenAgentRunner
    • create_autogen_runner(...)
    • openagents_tool_to_autogen(...)
    • autogen_tool_to_openagents(...)
  • exported the new AutoGen runner helpers from src/openagents/agents/__init__.py
  • added the autogen optional extra and included it in openagents[all]
  • added tests/agents/test_autogen_agent.py

Implementation notes

This follows the existing integration-runner pattern used for other frameworks, while aligning the AutoGen wrapper with documented AutoGen 0.7.5 behavior:

  • converted OpenAgents tools now expose stable schema-bearing AutoGen tool definitions instead of a generic **kwargs wrapper
  • runtime tool injection is limited to supported mutable tool containers and no longer assumes undocumented mutation APIs
  • run_stream() is consumed as an async generator and uses the terminal TaskResult
  • output extraction prefers final message content from TaskResult.messages

The current integration expects a live AutoGen entity object to be passed into the runner from Python code. It does not add YAML/factory-based AutoGen loading.

Validation

Automated:

  • pytest tests/agents/test_autogen_agent.py -v
  • pytest tests/agents/test_langchain_agent.py -v
  • pytest tests/agents -v
  • flake8 src/openagents/agents/autogen_agent.py tests/agents/test_autogen_agent.py

Manual:

  • started a minimal external AutoGen-style test agent wrapped by AutoGenAgentRunner
  • confirmed the agent appears on the network / in the UI
  • confirmed disconnect / reconnect behavior
  • confirmed direct message round-trip through the runner using the external harness

Related issue

Bermpje added 3 commits March 9, 2026 17:39
…in pyproject.toml

- Introduced autogen-core and autogen-agentchat as optional dependencies for enhanced functionality.
- Updated the 'all' optional dependencies list to include 'autogen' alongside existing packages.
- Added AutoGenAgentRunner for managing AutoGen entities within the OpenAgents framework.
- Implemented conversion functions to facilitate interaction between OpenAgents tools and AutoGen tools.
- Introduced unit tests for AutoGen agent integration, covering conversion and runner functionalities.
- Updated __init__.py to include new AutoGen components in the public API.
…uctions

- Introduced a code example for wrapping existing AutoGen agents or teams using AutoGenAgentRunner.
- Added instructions for installing optional dependencies required for AutoGen integration.
- Clarified the expectations for the AutoGen integration regarding live Python objects.
Copilot AI review requested due to automatic review settings March 9, 2026 17:12
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 9, 2026

@Bermpje is attempting to deploy a commit to the Raphael's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an AutoGenAgentRunner integration so Microsoft AutoGen agents and teams can participate in OpenAgents networks, following the same integration-runner pattern already established for LangChain, LlamaIndex, CrewAI, and PydanticAI.

Changes:

  • Added src/openagents/agents/autogen_agent.py with AutoGenAgentRunner, create_autogen_runner, openagents_tool_to_autogen, and autogen_tool_to_openagents — the core of the integration
  • Exported the new symbols from src/openagents/agents/__init__.py and added the autogen optional extra to pyproject.toml
  • Added regression test coverage in tests/agents/test_autogen_agent.py and a usage example in the docs

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/openagents/agents/autogen_agent.py Core AutoGen runner: tool converters, event filtering, streaming support, and schema-preserving tool adapter
src/openagents/agents/__init__.py Exports four new AutoGen symbols for public API access
pyproject.toml Adds autogen optional extra (autogen-core>=0.7.5, autogen-agentchat>=0.7.5) and includes it in openagents[all]
tests/agents/test_autogen_agent.py Unit tests covering tool conversion, event filtering, streaming, error handling, and package exports
docs/updates/2025-12-19-admin-dashboard.mdx Adds AutoGen integration usage example and install instructions to the docs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +477 to +483
metadata = {
"source_id": context.incoming_event.source_id,
"thread_id": context.incoming_thread_id,
"event_id": context.incoming_event.event_id,
"event_name": context.incoming_event.event_name,
}
del metadata
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The metadata dictionary is constructed and then immediately deleted via del metadata without ever being used. This is dead code that adds noise and may indicate an incomplete implementation — the context metadata (source_id, thread_id, event_id, event_name) is never passed to the AutoGen entity, meaning the invoked method has no way to correlate the call with the original OpenAgents event. The metadata dict should either be removed entirely, or used (for example, passed as context to the run call if the AutoGen API supports it).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the dead code. This was scaffolding for future context propagation but AutoGen's run() API doesn't have a standard metadata parameter to pass it to.

Comment on lines +213 to +214
args_model = autogen_tool.args_type()
args = args_model(**kwargs)
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

There is a two-step instantiation bug when building the args model. autogen_tool.args_type is a Pydantic model class. The code calls autogen_tool.args_type() with no arguments to get args_model, which produces an empty instance, and then calls args_model(**kwargs) on that instance, which will raise a TypeError because Pydantic model instances are not callable. The correct pattern is to call the class directly with the kwargs: args = autogen_tool.args_type(**kwargs), eliminating the intermediate args_model variable entirely.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Valid bug — args_type is a Pydantic model class, so args_type() creates an empty instance which isn't callable with (**kwargs). Fixed to call the class directly: args = autogen_tool.args_type(**kwargs).

Comment on lines +97 to +102
"""Test converting OpenAgents tool to AutoGen FunctionTool."""
from openagents.agents.autogen_agent import openagents_tool_to_autogen

autogen_tool = openagents_tool_to_autogen(sample_openagents_tool)
assert autogen_tool is not None
assert isinstance(autogen_tool, FunctionTool)
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The test docstring says "Test converting OpenAgents tool to AutoGen FunctionTool" and the assertion checks isinstance(autogen_tool, FunctionTool), but openagents_tool_to_autogen does not return a FunctionTool — it returns a custom OpenAgentsAutoGenTool that subclasses BaseTool directly. This isinstance check will fail when AutoGen is installed and the test runs, because OpenAgentsAutoGenTool is not derived from FunctionTool. The assertion should instead check for BaseTool, e.g., by importing BaseTool from autogen_core.tools and using isinstance(autogen_tool, BaseTool).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct — openagents_tool_to_autogen returns OpenAgentsAutoGenTool which subclasses BaseTool, not FunctionTool. Fixed the assertion and docstring.

Bermpje added 8 commits March 9, 2026 18:22
…text

- Replaced binary file handling with text reading for pyproject.toml in the AutoGen agent tests.
- Enhanced assertions to check for the presence of 'autogen' in the optional dependencies directly from the text content.
… connection handling

- Implemented retry logic for network initialization to handle port conflicts.
- Added health check for HTTP readiness after network startup.
- Improved connection assertions for admin, developer, and user clients to ensure successful connections.
- Added assertion for file upload response to verify successful uploads.
- Added installation of backend dependencies from requirements.txt to the pytest workflow for improved test environment setup.
- Updated the test for pyproject.toml to enhance the assertion for the presence of 'autogen' in the optional dependencies.
- Replaced the previous assertion with a more robust check that retrieves the relevant line containing 'openagents[' and verifies 'autogen' is included.
…onnection handling

- Implemented retry logic for network initialization to handle port conflicts.
- Added health check for HTTP readiness after network startup.
- Improved connection assertions for admin, analyst, and user clients to ensure successful connections.
…sertions

- Replaced random port assignment with OS-assigned free ports to prevent conflicts.
- Enhanced connection assertions for admin, developer, and user clients to ensure successful connections.
- Added checks to verify that network clients are connected before sending events.
- Introduced a utility function to obtain free TCP ports, replacing random port assignment.
- Updated network configuration to use loopback address (127.0.0.1) for consistency.
- Removed retry logic for network initialization, simplifying the setup process.
Copy link
Copy Markdown

@MontaEllis8 MontaEllis8 left a comment

Choose a reason for hiding this comment

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

✅ Code Review 通过

代码审查通过,建议合并。

- Remove unused metadata dict in _invoke_autogen (dead code)
- Fix args_type() double-instantiation: call args_type(**kwargs) directly
  instead of args_type()(**kwargs) which creates an empty model first
- Use BaseTool instead of FunctionTool in test isinstance check since
  openagents_tool_to_autogen may return any BaseTool subclass

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Help Wanted: AutoGen Agent Integration

3 participants