Skip to content

feat(beta): introduce dynamic_agent tool factory#2884

Merged
marklysze merged 10 commits into
mainfrom
feat/dynamic-agent
May 23, 2026
Merged

feat(beta): introduce dynamic_agent tool factory#2884
marklysze merged 10 commits into
mainfrom
feat/dynamic-agent

Conversation

@vvlrff
Copy link
Copy Markdown
Collaborator

@vvlrff vvlrff commented May 18, 2026

Summary

Adds a new advanced tool in autogen.beta.tools.dynamic that lets an Agent's LLM assemble an agent at runtime from a JSON spec it produces — name, system prompt, a subset of available tools, and an optional response schema — and immediately run it on a single objective.

What the parent LLM sees

A single tool with a JSON-schema'd argument:

create_and_run_agent(
    spec={
        "name": "math_helper",
        "prompt": ["You are precise."],
        "tool_names": ["calc"],
    },
    objective="Compute compound interest for 5y at 7% on 10k.",
) -> str

The tool reuses the existing AgentSpec model as its input, so the parent LLM may also pass a response_schema to constrain the child agent's reply to a structured shape:

create_and_run_agent(
    spec={
        "name": "extractor",
        "prompt": ["Extract numeric answer."],
        "tool_names": [],
        "response_schema": {
            "name": "Answer",
            "json_schema": {
                "type": "object",
                "properties": {"answer": {"type": "integer"}},
                "required": ["answer"],
            },
        },
    },
    objective="Compute 2+2.",
) -> str

What the developer writes

from autogen.beta import Agent
from autogen.beta.tools.dynamic import dynamic_agent

orchestrator = Agent(
    "orchestrator",
    config=cfg,
    tools=[
        read_file,
        grep,
        dynamic_agent(
            available_tools=[calc, web_search],
            config=cfg,
        ),
    ],
)

@vvlrff vvlrff requested a review from Lancetnik as a code owner May 18, 2026 20:47
@github-actions github-actions Bot added the beta label May 18, 2026
@vvlrff
Copy link
Copy Markdown
Collaborator Author

vvlrff commented May 18, 2026

@marklysze If the implementation is satisfactory, I will add documentation after approval.

Comment thread autogen/beta/tools/dynamic/factory.py Outdated
Comment thread autogen/beta/tools/dynamic/spec_input.py Outdated
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label May 22, 2026
Copy link
Copy Markdown
Collaborator

@marklysze marklysze left a comment

Choose a reason for hiding this comment

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

Very handy, thanks @vvlrff!

@marklysze marklysze enabled auto-merge May 23, 2026 00:18
@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2026

Codecov Report

❌ Patch coverage is 93.47826% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
autogen/beta/tools/dynamic/factory.py 88.88% 1 Missing and 2 partials ⚠️
Files with missing lines Coverage Δ
autogen/beta/tools/dynamic/__init__.py 100.00% <100.00%> (ø)
autogen/beta/tools/dynamic/handler.py 100.00% <100.00%> (ø)
autogen/beta/tools/dynamic/factory.py 88.88% <88.88%> (ø)

... and 36 files with indirect coverage changes

🚀 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.

@marklysze marklysze added this pull request to the merge queue May 23, 2026
Merged via the queue into main with commit c3a6de7 May 23, 2026
29 checks passed
@marklysze marklysze deleted the feat/dynamic-agent branch May 23, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants