Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Autogen GalleryBuilder Build

From Leeroopedia
Knowledge Sources
Domains Agent Frameworks, Component Registries, Builder Pattern, Reusable Components
Last Updated 2026-02-11 00:00 GMT

Overview

Concrete tool for assembling a gallery of reusable multi-agent components provided by the autogenstudio package.

Description

The GalleryBuilder class uses the builder pattern to incrementally construct a GalleryConfig containing serialized AutoGen components. It provides add_team(), add_agent(), add_model(), add_tool(), add_termination(), and add_workbench() methods that accept a ComponentModel along with optional label and description overrides. The set_metadata() method configures gallery-level metadata (author, version, tags, license, category). Calling build() produces the final GalleryConfig object containing all registered components organized by category.

Usage

Use GalleryBuilder when you need to programmatically create a component gallery for AutoGen Studio, define a default set of components for the UI, or export a curated component library as JSON.

Code Reference

Source Location

  • Repository: Microsoft AutoGen
  • File: python/packages/autogen-studio/autogenstudio/gallery/builder.py (L33-L151)

Signature

class GalleryBuilder:
    """Enhanced builder class for creating AutoGen component galleries with custom labels."""

    def __init__(self, id: str, name: str, url: Optional[str] = None) -> None: ...

    def set_metadata(
        self,
        author: Optional[str] = None,
        version: Optional[str] = None,
        description: Optional[str] = None,
        tags: Optional[List[str]] = None,
        license: Optional[str] = None,
        category: Optional[str] = None,
    ) -> "GalleryBuilder": ...

    def add_team(
        self, team: ComponentModel, label: Optional[str] = None, description: Optional[str] = None
    ) -> "GalleryBuilder": ...

    def add_agent(
        self, agent: ComponentModel, label: Optional[str] = None, description: Optional[str] = None
    ) -> "GalleryBuilder": ...

    def add_model(
        self, model: ComponentModel, label: Optional[str] = None, description: Optional[str] = None
    ) -> "GalleryBuilder": ...

    def add_tool(
        self, tool: ComponentModel, label: Optional[str] = None, description: Optional[str] = None
    ) -> "GalleryBuilder": ...

    def add_termination(
        self, termination: ComponentModel, label: Optional[str] = None, description: Optional[str] = None
    ) -> "GalleryBuilder": ...

    def add_workbench(
        self, workbench: ComponentModel, label: Optional[str] = None, description: Optional[str] = None
    ) -> "GalleryBuilder": ...

    def build(self) -> GalleryConfig: ...

Import

from autogenstudio.gallery.builder import GalleryBuilder

I/O Contract

Inputs (constructor)

Name Type Required Description
id str Yes Unique identifier for the gallery (e.g., "gallery_default")
name str Yes Human-readable name for the gallery
url Optional[str] No (default None) URL where the gallery can be fetched from

Inputs (add_* methods)

Name Type Required Description
team / agent / model / tool / termination / workbench ComponentModel Yes The serialized component to add (obtained via dump_component())
label Optional[str] No Human-readable label override for the component
description Optional[str] No Description override for the component

Inputs (set_metadata)

Name Type Required Description
author Optional[str] No Author name for the gallery
version Optional[str] No Version string for the gallery
description Optional[str] No Description of the gallery
tags Optional[List[str]] No List of tags for categorization
license Optional[str] No License identifier (e.g., "MIT")
category Optional[str] No Gallery category (e.g., "conversation")

Outputs

Name Type Description
GalleryConfig GalleryConfig Complete gallery configuration containing all registered components organized by category, with metadata

Usage Examples

Basic Example

from autogenstudio.gallery.builder import GalleryBuilder
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import MaxMessageTermination
from autogen_agentchat.teams import RoundRobinGroupChat

# Create builder
builder = GalleryBuilder(id="my_gallery", name="My Custom Gallery")

# Set metadata
builder.set_metadata(
    author="My Team",
    version="1.0.0",
    description="A custom gallery for our project",
    tags=["custom", "research"],
)

# Add a model client
model = OpenAIChatCompletionClient(model="gpt-4o-mini")
builder.add_model(
    model.dump_component(),
    label="GPT-4o Mini",
    description="OpenAI GPT-4o-mini model client",
)

# Add an agent
agent = AssistantAgent(
    name="assistant",
    model_client=model,
    system_message="You are a helpful assistant.",
)
builder.add_agent(agent.dump_component(), label="Basic Assistant")

# Add a termination condition
termination = MaxMessageTermination(max_messages=10)
builder.add_termination(termination.dump_component(), label="Max 10 Messages")

# Add a team
team = RoundRobinGroupChat(participants=[agent], termination_condition=termination)
builder.add_team(team.dump_component(), label="Simple Team")

# Build the gallery
gallery = builder.build()

# Export as JSON
with open("gallery.json", "w") as f:
    f.write(gallery.model_dump_json(indent=2))

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment