426 lines
20 KiB
Python
Raw Normal View History

import os
from datetime import datetime
from typing import List, Optional
import anthropic
from autogen_agentchat.agents import AssistantAgent, UserProxyAgent
from autogen_agentchat.conditions import MaxMessageTermination, TextMentionTermination
from autogen_agentchat.teams import RoundRobinGroupChat, SelectorGroupChat
from autogen_core import ComponentModel
from autogen_core.models import ModelInfo
from autogen_ext.agents.web_surfer import MultimodalWebSurfer
Add Token Streaming in AGS , Support Env variables (#5659) <!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> This PR has 3 main improvements. - Token streaming - Adds support for environment variables in the app settings - Updates AGS to persist Gallery entry in db. ## Adds Token Streaming in AGS. Agentchat now supports streaming of tokens via `ModelClientStreamingChunkEvent `. This PR is to track progress on supporting that in the AutoGen Studio UI. If `model_client_stream` is enabled in an assitant agent, then token will be streamed in UI. ```python streaming_assistant = AssistantAgent( name="assistant", model_client=model_client, system_message="You are a helpful assistant.", model_client_stream=True, # Enable streaming tokens. ) ``` https://github.com/user-attachments/assets/74d43d78-6359-40c3-a78e-c84dcb5e02a1 ## Env Variables Also adds support for env variables in AGS Settings You can set env variables that are loaded just before a team is run. Handy to set variable to be used by tools etc. <img width="1291" alt="image" src="https://github.com/user-attachments/assets/437b9d90-ccee-42f7-be5d-94ab191afd67" /> > Note: the set variables are available to the server process. <!-- 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 #1234" --> Closes #5627 Closes #5662 Closes #5619 ## 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.
2025-02-25 07:21:08 -08:00
from autogen_ext.code_executors.local import LocalCommandLineCodeExecutor
from autogen_ext.models.anthropic import AnthropicChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.models.openai._openai_client import AzureOpenAIChatCompletionClient
Add Token Streaming in AGS , Support Env variables (#5659) <!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> This PR has 3 main improvements. - Token streaming - Adds support for environment variables in the app settings - Updates AGS to persist Gallery entry in db. ## Adds Token Streaming in AGS. Agentchat now supports streaming of tokens via `ModelClientStreamingChunkEvent `. This PR is to track progress on supporting that in the AutoGen Studio UI. If `model_client_stream` is enabled in an assitant agent, then token will be streamed in UI. ```python streaming_assistant = AssistantAgent( name="assistant", model_client=model_client, system_message="You are a helpful assistant.", model_client_stream=True, # Enable streaming tokens. ) ``` https://github.com/user-attachments/assets/74d43d78-6359-40c3-a78e-c84dcb5e02a1 ## Env Variables Also adds support for env variables in AGS Settings You can set env variables that are loaded just before a team is run. Handy to set variable to be used by tools etc. <img width="1291" alt="image" src="https://github.com/user-attachments/assets/437b9d90-ccee-42f7-be5d-94ab191afd67" /> > Note: the set variables are available to the server process. <!-- 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 #1234" --> Closes #5627 Closes #5662 Closes #5619 ## 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.
2025-02-25 07:21:08 -08:00
from autogen_ext.tools.code_execution import PythonCodeExecutionTool
Add Token Streaming in AGS , Support Env variables (#5659) <!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> This PR has 3 main improvements. - Token streaming - Adds support for environment variables in the app settings - Updates AGS to persist Gallery entry in db. ## Adds Token Streaming in AGS. Agentchat now supports streaming of tokens via `ModelClientStreamingChunkEvent `. This PR is to track progress on supporting that in the AutoGen Studio UI. If `model_client_stream` is enabled in an assitant agent, then token will be streamed in UI. ```python streaming_assistant = AssistantAgent( name="assistant", model_client=model_client, system_message="You are a helpful assistant.", model_client_stream=True, # Enable streaming tokens. ) ``` https://github.com/user-attachments/assets/74d43d78-6359-40c3-a78e-c84dcb5e02a1 ## Env Variables Also adds support for env variables in AGS Settings You can set env variables that are loaded just before a team is run. Handy to set variable to be used by tools etc. <img width="1291" alt="image" src="https://github.com/user-attachments/assets/437b9d90-ccee-42f7-be5d-94ab191afd67" /> > Note: the set variables are available to the server process. <!-- 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 #1234" --> Closes #5627 Closes #5662 Closes #5619 ## 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.
2025-02-25 07:21:08 -08:00
from autogenstudio.datamodel import GalleryComponents, GalleryConfig, GalleryMetadata
from . import tools as tools
class GalleryBuilder:
"""Enhanced builder class for creating AutoGen component galleries with custom labels."""
def __init__(self, id: str, name: str, url: Optional[str] = None):
self.id = id
self.name = name
self.url: Optional[str] = url
self.teams: List[ComponentModel] = []
self.agents: List[ComponentModel] = []
self.models: List[ComponentModel] = []
self.tools: List[ComponentModel] = []
self.terminations: List[ComponentModel] = []
# Default metadata
self.metadata = GalleryMetadata(
author="AutoGen Team",
version="1.0.0",
description="",
tags=[],
license="MIT",
category="conversation",
)
def _update_component_metadata(
self, component: ComponentModel, label: Optional[str] = None, description: Optional[str] = None
) -> ComponentModel:
"""Helper method to update component metadata."""
if label is not None:
component.label = label
if description is not None:
component.description = description
return component
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":
"""Update gallery metadata."""
if author:
self.metadata.author = author
if version:
self.metadata.version = version
if description:
self.metadata.description = description
if tags:
self.metadata.tags = tags
if license:
self.metadata.license = license
if category:
self.metadata.category = category
return self
def add_team(
self, team: ComponentModel, label: Optional[str] = None, description: Optional[str] = None
) -> "GalleryBuilder":
"""Add a team component to the gallery with optional custom label and description."""
self.teams.append(self._update_component_metadata(team, label, description))
return self
def add_agent(
self, agent: ComponentModel, label: Optional[str] = None, description: Optional[str] = None
) -> "GalleryBuilder":
"""Add an agent component to the gallery with optional custom label and description."""
self.agents.append(self._update_component_metadata(agent, label, description))
return self
def add_model(
self, model: ComponentModel, label: Optional[str] = None, description: Optional[str] = None
) -> "GalleryBuilder":
"""Add a model component to the gallery with optional custom label and description."""
self.models.append(self._update_component_metadata(model, label, description))
return self
def add_tool(
self, tool: ComponentModel, label: Optional[str] = None, description: Optional[str] = None
) -> "GalleryBuilder":
"""Add a tool component to the gallery with optional custom label and description."""
self.tools.append(self._update_component_metadata(tool, label, description))
return self
def add_termination(
self, termination: ComponentModel, label: Optional[str] = None, description: Optional[str] = None
) -> "GalleryBuilder":
"""Add a termination condition component with optional custom label and description."""
self.terminations.append(self._update_component_metadata(termination, label, description))
return self
Add Token Streaming in AGS , Support Env variables (#5659) <!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> This PR has 3 main improvements. - Token streaming - Adds support for environment variables in the app settings - Updates AGS to persist Gallery entry in db. ## Adds Token Streaming in AGS. Agentchat now supports streaming of tokens via `ModelClientStreamingChunkEvent `. This PR is to track progress on supporting that in the AutoGen Studio UI. If `model_client_stream` is enabled in an assitant agent, then token will be streamed in UI. ```python streaming_assistant = AssistantAgent( name="assistant", model_client=model_client, system_message="You are a helpful assistant.", model_client_stream=True, # Enable streaming tokens. ) ``` https://github.com/user-attachments/assets/74d43d78-6359-40c3-a78e-c84dcb5e02a1 ## Env Variables Also adds support for env variables in AGS Settings You can set env variables that are loaded just before a team is run. Handy to set variable to be used by tools etc. <img width="1291" alt="image" src="https://github.com/user-attachments/assets/437b9d90-ccee-42f7-be5d-94ab191afd67" /> > Note: the set variables are available to the server process. <!-- 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 #1234" --> Closes #5627 Closes #5662 Closes #5619 ## 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.
2025-02-25 07:21:08 -08:00
def build(self) -> GalleryConfig:
"""Build and return the complete gallery."""
# Update timestamps
Add Token Streaming in AGS , Support Env variables (#5659) <!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> This PR has 3 main improvements. - Token streaming - Adds support for environment variables in the app settings - Updates AGS to persist Gallery entry in db. ## Adds Token Streaming in AGS. Agentchat now supports streaming of tokens via `ModelClientStreamingChunkEvent `. This PR is to track progress on supporting that in the AutoGen Studio UI. If `model_client_stream` is enabled in an assitant agent, then token will be streamed in UI. ```python streaming_assistant = AssistantAgent( name="assistant", model_client=model_client, system_message="You are a helpful assistant.", model_client_stream=True, # Enable streaming tokens. ) ``` https://github.com/user-attachments/assets/74d43d78-6359-40c3-a78e-c84dcb5e02a1 ## Env Variables Also adds support for env variables in AGS Settings You can set env variables that are loaded just before a team is run. Handy to set variable to be used by tools etc. <img width="1291" alt="image" src="https://github.com/user-attachments/assets/437b9d90-ccee-42f7-be5d-94ab191afd67" /> > Note: the set variables are available to the server process. <!-- 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 #1234" --> Closes #5627 Closes #5662 Closes #5619 ## 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.
2025-02-25 07:21:08 -08:00
# self.metadata.updated_at = datetime.now()
Add Token Streaming in AGS , Support Env variables (#5659) <!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> This PR has 3 main improvements. - Token streaming - Adds support for environment variables in the app settings - Updates AGS to persist Gallery entry in db. ## Adds Token Streaming in AGS. Agentchat now supports streaming of tokens via `ModelClientStreamingChunkEvent `. This PR is to track progress on supporting that in the AutoGen Studio UI. If `model_client_stream` is enabled in an assitant agent, then token will be streamed in UI. ```python streaming_assistant = AssistantAgent( name="assistant", model_client=model_client, system_message="You are a helpful assistant.", model_client_stream=True, # Enable streaming tokens. ) ``` https://github.com/user-attachments/assets/74d43d78-6359-40c3-a78e-c84dcb5e02a1 ## Env Variables Also adds support for env variables in AGS Settings You can set env variables that are loaded just before a team is run. Handy to set variable to be used by tools etc. <img width="1291" alt="image" src="https://github.com/user-attachments/assets/437b9d90-ccee-42f7-be5d-94ab191afd67" /> > Note: the set variables are available to the server process. <!-- 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 #1234" --> Closes #5627 Closes #5662 Closes #5619 ## 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.
2025-02-25 07:21:08 -08:00
return GalleryConfig(
id=self.id,
name=self.name,
url=self.url,
metadata=self.metadata,
Improve Gallery Editor UX in AGS (#5613) <!-- 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? Fixes the problem where Gallery items could only be modified via JSON This PR does the following - Refactor TeamBuilder to have modular component editor UI primarily focused on editing each component type. - Refactor the Gallery UX - improve layout to use tabs for each component type - enable editing of each component item by reusing the component editor - Enable switching between form editing and UI editing for coponent editor view This way, gallery items can be readily modified and then reused in the component library in team builder. It also implements an upate to the Gallery data structure to make it more intuitive - it has a components field that has teams, agents, models ... <img width="1598" alt="image" src="https://github.com/user-attachments/assets/3c3a228a-0bd2-4fc1-85ec-c9685c80bf72" /> <img width="1614" alt="image" src="https://github.com/user-attachments/assets/5b6ed840-9c48-47bc-8c17-2aa50c7dcb99" /> <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #5465 Closes #5047 cc @nour-bouzid @balakreshnan @EItanya @joslat @IustinT @leonG7 ## 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.
2025-02-20 21:51:05 -08:00
components=GalleryComponents(
teams=self.teams,
Improve Gallery Editor UX in AGS (#5613) <!-- 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? Fixes the problem where Gallery items could only be modified via JSON This PR does the following - Refactor TeamBuilder to have modular component editor UI primarily focused on editing each component type. - Refactor the Gallery UX - improve layout to use tabs for each component type - enable editing of each component item by reusing the component editor - Enable switching between form editing and UI editing for coponent editor view This way, gallery items can be readily modified and then reused in the component library in team builder. It also implements an upate to the Gallery data structure to make it more intuitive - it has a components field that has teams, agents, models ... <img width="1598" alt="image" src="https://github.com/user-attachments/assets/3c3a228a-0bd2-4fc1-85ec-c9685c80bf72" /> <img width="1614" alt="image" src="https://github.com/user-attachments/assets/5b6ed840-9c48-47bc-8c17-2aa50c7dcb99" /> <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #5465 Closes #5047 cc @nour-bouzid @balakreshnan @EItanya @joslat @IustinT @leonG7 ## 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.
2025-02-20 21:51:05 -08:00
agents=self.agents,
models=self.models,
tools=self.tools,
terminations=self.terminations,
),
)
Add Token Streaming in AGS , Support Env variables (#5659) <!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> This PR has 3 main improvements. - Token streaming - Adds support for environment variables in the app settings - Updates AGS to persist Gallery entry in db. ## Adds Token Streaming in AGS. Agentchat now supports streaming of tokens via `ModelClientStreamingChunkEvent `. This PR is to track progress on supporting that in the AutoGen Studio UI. If `model_client_stream` is enabled in an assitant agent, then token will be streamed in UI. ```python streaming_assistant = AssistantAgent( name="assistant", model_client=model_client, system_message="You are a helpful assistant.", model_client_stream=True, # Enable streaming tokens. ) ``` https://github.com/user-attachments/assets/74d43d78-6359-40c3-a78e-c84dcb5e02a1 ## Env Variables Also adds support for env variables in AGS Settings You can set env variables that are loaded just before a team is run. Handy to set variable to be used by tools etc. <img width="1291" alt="image" src="https://github.com/user-attachments/assets/437b9d90-ccee-42f7-be5d-94ab191afd67" /> > Note: the set variables are available to the server process. <!-- 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 #1234" --> Closes #5627 Closes #5662 Closes #5619 ## 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.
2025-02-25 07:21:08 -08:00
def create_default_gallery() -> GalleryConfig:
"""Create a default gallery with all components including calculator and web surfer teams."""
# model clients require API keys to be set in the environment or passed in
# as arguments. For testing purposes, we set them to "test" if not already set.
for key in ["OPENAI_API_KEY", "AZURE_OPENAI_API_KEY", "ANTHROPIC_API_KEY"]:
if not os.environ.get(key):
os.environ[key] = "test"
# url = "https://raw.githubusercontent.com/microsoft/autogen/refs/heads/main/python/packages/autogen-studio/autogenstudio/gallery/default.json"
builder = GalleryBuilder(id="gallery_default", name="Default Component Gallery")
# Set metadata
builder.set_metadata(
description="A default gallery containing basic components for human-in-loop conversations",
tags=["human-in-loop", "assistant", "web agents"],
category="conversation",
)
# Create base model client
base_model = OpenAIChatCompletionClient(model="gpt-4o-mini")
builder.add_model(base_model.dump_component(), label="OpenAI GPT-4o Mini", description="OpenAI GPT-4o-mini")
# Create Mistral vllm model
mistral_vllm_model = OpenAIChatCompletionClient(
model="TheBloke/Mistral-7B-Instruct-v0.2-GGUF",
base_url="http://localhost:1234/v1",
model_info=ModelInfo(
vision=False, function_calling=True, json_output=False, family="unknown", structured_output=False
),
)
builder.add_model(
mistral_vllm_model.dump_component(),
label="Mistral-7B Local",
description="Local Mistral-7B model client for instruction-based generation (Ollama, LMStudio).",
)
anthropic_model = AnthropicChatCompletionClient(model="claude-3-7-sonnet-20250219")
builder.add_model(
anthropic_model.dump_component(),
label="Anthropic Claude-3-7",
description="Anthropic Claude-3 model client.",
)
# create an azure mode
az_model_client = AzureOpenAIChatCompletionClient(
azure_deployment="{your-azure-deployment}",
model="gpt-4o-mini",
api_version="2024-06-01",
azure_endpoint="https://{your-custom-endpoint}.openai.azure.com/",
api_key="test",
)
builder.add_model(
az_model_client.dump_component(),
label="AzureOpenAI GPT-4o-mini",
description="GPT-4o Mini Azure OpenAI model client.",
)
builder.add_tool(
tools.calculator_tool.dump_component(),
label="Calculator Tool",
description="A tool that performs basic arithmetic operations (addition, subtraction, multiplication, division).",
)
# Create calculator assistant agent
calc_assistant = AssistantAgent(
name="assistant_agent",
system_message="You are a helpful assistant. Solve tasks carefully. When done, say TERMINATE.",
model_client=base_model,
tools=[tools.calculator_tool],
)
Support Component Validation API in AGS (#5503) <!-- 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? It is useful to rapidly validate any changes to a team structure as teams are built either via drag and drop or by modifying the underlying spec You can now “validate” your team. The key ideas are as follows - Each team is based on some Component Config specification which is a pedantic model underneath. - Validation is 3 pronged based on a ValidatorService class - Data model validation (validate component schema) - Instantiation validation (validate component can be instantiated) - Provider validation, component_type validation (validate that provider exists and can be imported) - UX: each time a component is **loaded or saved**, it is automatically validated and any errors shown (via a server endpoint). This way, the developer immediately knows if updates to the configuration is wrong or has errors. > Note: this is different from actually running the component against a task. Currently you can run the entire team. In a separate PR we will implement ability to run/test other components. <img width="1360" alt="image" src="https://github.com/user-attachments/assets/d61095b7-0b07-463a-b4b2-5c50ded750f6" /> <img width="1368" alt="image" src="https://github.com/user-attachments/assets/09a1677e-76e8-44a4-9749-15c27457efbb" /> <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number Closes #4616 <!-- For example: "Closes #1234" --> ## Checks - [ ] I've included any doc changes needed for https://microsoft.github.io/autogen/. See https://microsoft.github.io/autogen/docs/Contribute#documentation 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.
2025-02-12 09:29:43 -08:00
builder.add_agent(
calc_assistant.dump_component(), description="An agent that provides assistance with ability to use tools."
)
# Create termination conditions
calc_text_term = TextMentionTermination(text="TERMINATE")
calc_max_term = MaxMessageTermination(max_messages=10)
calc_or_term = calc_text_term | calc_max_term
builder.add_termination(calc_text_term.dump_component())
builder.add_termination(calc_max_term.dump_component())
Improve Gallery Editor UX in AGS (#5613) <!-- 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? Fixes the problem where Gallery items could only be modified via JSON This PR does the following - Refactor TeamBuilder to have modular component editor UI primarily focused on editing each component type. - Refactor the Gallery UX - improve layout to use tabs for each component type - enable editing of each component item by reusing the component editor - Enable switching between form editing and UI editing for coponent editor view This way, gallery items can be readily modified and then reused in the component library in team builder. It also implements an upate to the Gallery data structure to make it more intuitive - it has a components field that has teams, agents, models ... <img width="1598" alt="image" src="https://github.com/user-attachments/assets/3c3a228a-0bd2-4fc1-85ec-c9685c80bf72" /> <img width="1614" alt="image" src="https://github.com/user-attachments/assets/5b6ed840-9c48-47bc-8c17-2aa50c7dcb99" /> <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #5465 Closes #5047 cc @nour-bouzid @balakreshnan @EItanya @joslat @IustinT @leonG7 ## 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.
2025-02-20 21:51:05 -08:00
builder.add_termination(
calc_or_term.dump_component(),
label="OR Termination",
description="Termination condition that ends the conversation when either a message contains 'TERMINATE' or the maximum number of messages is reached.",
)
# Create calculator team
calc_team = RoundRobinGroupChat(participants=[calc_assistant], termination_condition=calc_or_term)
builder.add_team(
calc_team.dump_component(),
Support Component Validation API in AGS (#5503) <!-- 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? It is useful to rapidly validate any changes to a team structure as teams are built either via drag and drop or by modifying the underlying spec You can now “validate” your team. The key ideas are as follows - Each team is based on some Component Config specification which is a pedantic model underneath. - Validation is 3 pronged based on a ValidatorService class - Data model validation (validate component schema) - Instantiation validation (validate component can be instantiated) - Provider validation, component_type validation (validate that provider exists and can be imported) - UX: each time a component is **loaded or saved**, it is automatically validated and any errors shown (via a server endpoint). This way, the developer immediately knows if updates to the configuration is wrong or has errors. > Note: this is different from actually running the component against a task. Currently you can run the entire team. In a separate PR we will implement ability to run/test other components. <img width="1360" alt="image" src="https://github.com/user-attachments/assets/d61095b7-0b07-463a-b4b2-5c50ded750f6" /> <img width="1368" alt="image" src="https://github.com/user-attachments/assets/09a1677e-76e8-44a4-9749-15c27457efbb" /> <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number Closes #4616 <!-- For example: "Closes #1234" --> ## Checks - [ ] I've included any doc changes needed for https://microsoft.github.io/autogen/. See https://microsoft.github.io/autogen/docs/Contribute#documentation 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.
2025-02-12 09:29:43 -08:00
label="RoundRobin Team",
description="A single AssistantAgent (with a calculator tool) in a RoundRobinGroupChat team. ",
)
Support Component Validation API in AGS (#5503) <!-- 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? It is useful to rapidly validate any changes to a team structure as teams are built either via drag and drop or by modifying the underlying spec You can now “validate” your team. The key ideas are as follows - Each team is based on some Component Config specification which is a pedantic model underneath. - Validation is 3 pronged based on a ValidatorService class - Data model validation (validate component schema) - Instantiation validation (validate component can be instantiated) - Provider validation, component_type validation (validate that provider exists and can be imported) - UX: each time a component is **loaded or saved**, it is automatically validated and any errors shown (via a server endpoint). This way, the developer immediately knows if updates to the configuration is wrong or has errors. > Note: this is different from actually running the component against a task. Currently you can run the entire team. In a separate PR we will implement ability to run/test other components. <img width="1360" alt="image" src="https://github.com/user-attachments/assets/d61095b7-0b07-463a-b4b2-5c50ded750f6" /> <img width="1368" alt="image" src="https://github.com/user-attachments/assets/09a1677e-76e8-44a4-9749-15c27457efbb" /> <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number Closes #4616 <!-- For example: "Closes #1234" --> ## Checks - [ ] I've included any doc changes needed for https://microsoft.github.io/autogen/. See https://microsoft.github.io/autogen/docs/Contribute#documentation 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.
2025-02-12 09:29:43 -08:00
critic_agent = AssistantAgent(
name="critic_agent",
system_message="You are a helpful assistant. Critique the assistant's output and suggest improvements.",
description="an agent that critiques and improves the assistant's output",
model_client=base_model,
)
selector_default_team = SelectorGroupChat(
participants=[calc_assistant, critic_agent], termination_condition=calc_or_term, model_client=base_model
)
builder.add_team(
selector_default_team.dump_component(),
label="Selector Team",
description="A team with 2 agents - an AssistantAgent (with a calculator tool) and a CriticAgent in a SelectorGroupChat team.",
)
# Create web surfer agent
websurfer_agent = MultimodalWebSurfer(
name="websurfer_agent",
description="an agent that solves tasks by browsing the web",
model_client=base_model,
headless=True,
)
Improve Gallery Editor UX in AGS (#5613) <!-- 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? Fixes the problem where Gallery items could only be modified via JSON This PR does the following - Refactor TeamBuilder to have modular component editor UI primarily focused on editing each component type. - Refactor the Gallery UX - improve layout to use tabs for each component type - enable editing of each component item by reusing the component editor - Enable switching between form editing and UI editing for coponent editor view This way, gallery items can be readily modified and then reused in the component library in team builder. It also implements an upate to the Gallery data structure to make it more intuitive - it has a components field that has teams, agents, models ... <img width="1598" alt="image" src="https://github.com/user-attachments/assets/3c3a228a-0bd2-4fc1-85ec-c9685c80bf72" /> <img width="1614" alt="image" src="https://github.com/user-attachments/assets/5b6ed840-9c48-47bc-8c17-2aa50c7dcb99" /> <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #5465 Closes #5047 cc @nour-bouzid @balakreshnan @EItanya @joslat @IustinT @leonG7 ## 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.
2025-02-20 21:51:05 -08:00
builder.add_agent(
websurfer_agent.dump_component(),
label="Web Surfer Agent",
description="An agent that solves tasks by browsing the web using a headless browser.",
)
# Create verification assistant
verification_assistant = AssistantAgent(
name="assistant_agent",
description="an agent that verifies and summarizes information",
system_message="You are a task verification assistant who is working with a web surfer agent to solve tasks. At each point, check if the task has been completed as requested by the user. If the websurfer_agent responds and the task has not yet been completed, respond with what is left to do and then say 'keep going'. If and only when the task has been completed, summarize and present a final answer that directly addresses the user task in detail and then respond with TERMINATE.",
model_client=base_model,
)
Improve Gallery Editor UX in AGS (#5613) <!-- 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? Fixes the problem where Gallery items could only be modified via JSON This PR does the following - Refactor TeamBuilder to have modular component editor UI primarily focused on editing each component type. - Refactor the Gallery UX - improve layout to use tabs for each component type - enable editing of each component item by reusing the component editor - Enable switching between form editing and UI editing for coponent editor view This way, gallery items can be readily modified and then reused in the component library in team builder. It also implements an upate to the Gallery data structure to make it more intuitive - it has a components field that has teams, agents, models ... <img width="1598" alt="image" src="https://github.com/user-attachments/assets/3c3a228a-0bd2-4fc1-85ec-c9685c80bf72" /> <img width="1614" alt="image" src="https://github.com/user-attachments/assets/5b6ed840-9c48-47bc-8c17-2aa50c7dcb99" /> <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #5465 Closes #5047 cc @nour-bouzid @balakreshnan @EItanya @joslat @IustinT @leonG7 ## 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.
2025-02-20 21:51:05 -08:00
builder.add_agent(
verification_assistant.dump_component(),
label="Verification Assistant",
description="an agent that verifies and summarizes information",
)
# Create user proxy
web_user_proxy = UserProxyAgent(
name="user_proxy",
description="a human user that should be consulted only when the assistant_agent is unable to verify the information provided by the websurfer_agent",
)
builder.add_agent(web_user_proxy.dump_component())
# Create web surfer team termination conditions
web_max_term = MaxMessageTermination(max_messages=20)
web_text_term = TextMentionTermination(text="TERMINATE")
web_termination = web_max_term | web_text_term
# Create web surfer team
selector_prompt = """You are the cordinator of role play game. The following roles are available:
{roles}. Given a task, the websurfer_agent will be tasked to address it by browsing the web and providing information. The assistant_agent will be tasked with verifying the information provided by the websurfer_agent and summarizing the information to present a final answer to the user. If the task needs assistance from a human user (e.g., providing feedback, preferences, or the task is stalled), you should select the user_proxy role to provide the necessary information.
Read the following conversation. Then select the next role from {participants} to play. Only return the role.
{history}
Read the above conversation. Then select the next role from {participants} to play. Only return the role."""
websurfer_team = SelectorGroupChat(
participants=[websurfer_agent, verification_assistant, web_user_proxy],
selector_prompt=selector_prompt,
model_client=base_model,
termination_condition=web_termination,
)
2025-02-07 15:37:44 -08:00
builder.add_team(
websurfer_team.dump_component(),
label="Web Agent Team (Operator)",
Enable LLM Call Observability in AGS (#5457) <!-- 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. --> It is often helpful to inspect the raw request and response to/from an LLM as agents act. This PR, does the following: - Updates TeamManager to yield LLMCallEvents from core library - Run in an async background task to listen for LLMCallEvent JIT style when a team is run - Add events to an async queue and - yield those events in addition to whatever actual agentchat team.run_stream yields. - Update the AGS UI to show those LLMCallEvents in the messages section as a team runs - Add settings panel to show/hide llm call events in messages. - Minor updates to default team <img width="1539" alt="image" src="https://github.com/user-attachments/assets/bfbb19fe-3560-4faa-b600-7dd244e0e974" /> <img width="1554" alt="image" src="https://github.com/user-attachments/assets/775624f5-ba83-46e8-81ff-512bfeed6bab" /> <img width="1538" alt="image" src="https://github.com/user-attachments/assets/3becbf85-b75a-4506-adb7-e5575ebbaec4" /> ## Why are these changes needed? <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #5440 ## Checks - [ ] I've included any doc changes needed for https://microsoft.github.io/autogen/. See https://microsoft.github.io/autogen/docs/Contribute#documentation 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.
2025-02-08 20:50:12 -08:00
description="A team with 3 agents - a Web Surfer agent that can browse the web, a Verification Assistant that verifies and summarizes information, and a User Proxy that provides human feedback when needed.",
)
builder.add_tool(
tools.generate_image_tool.dump_component(),
label="Image Generation Tool",
description="A tool that generates images based on a text description using OpenAI's DALL-E model. Note: Requires OpenAI API key to function.",
)
builder.add_tool(
tools.fetch_webpage_tool.dump_component(),
2025-02-07 15:37:44 -08:00
label="Fetch Webpage Tool",
description="A tool that fetches the content of a webpage and converts it to markdown. Requires the requests and beautifulsoup4 library to function.",
)
builder.add_tool(
tools.bing_search_tool.dump_component(),
label="Bing Search Tool",
description="A tool that performs Bing searches using the Bing Web Search API. Requires the requests library, BING_SEARCH_KEY env variable to function.",
)
builder.add_tool(
tools.google_search_tool.dump_component(),
label="Google Search Tool",
description="A tool that performs Google searches using the Google Custom Search API. Requires the requests library, [GOOGLE_API_KEY, GOOGLE_CSE_ID] to be set, env variable to function.",
)
Add Token Streaming in AGS , Support Env variables (#5659) <!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> This PR has 3 main improvements. - Token streaming - Adds support for environment variables in the app settings - Updates AGS to persist Gallery entry in db. ## Adds Token Streaming in AGS. Agentchat now supports streaming of tokens via `ModelClientStreamingChunkEvent `. This PR is to track progress on supporting that in the AutoGen Studio UI. If `model_client_stream` is enabled in an assitant agent, then token will be streamed in UI. ```python streaming_assistant = AssistantAgent( name="assistant", model_client=model_client, system_message="You are a helpful assistant.", model_client_stream=True, # Enable streaming tokens. ) ``` https://github.com/user-attachments/assets/74d43d78-6359-40c3-a78e-c84dcb5e02a1 ## Env Variables Also adds support for env variables in AGS Settings You can set env variables that are loaded just before a team is run. Handy to set variable to be used by tools etc. <img width="1291" alt="image" src="https://github.com/user-attachments/assets/437b9d90-ccee-42f7-be5d-94ab191afd67" /> > Note: the set variables are available to the server process. <!-- 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 #1234" --> Closes #5627 Closes #5662 Closes #5619 ## 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.
2025-02-25 07:21:08 -08:00
code_executor = LocalCommandLineCodeExecutor(work_dir=".coding", timeout=360)
code_execution_tool = PythonCodeExecutionTool(code_executor)
builder.add_tool(
code_execution_tool.dump_component(),
label="Python Code Execution Tool",
description="A tool that executes Python code in a local environment.",
)
2025-02-07 15:37:44 -08:00
# Create deep research agent
model_client = OpenAIChatCompletionClient(model="gpt-4o", temperature=0.7)
research_assistant = AssistantAgent(
name="research_assistant",
description="A research assistant that performs web searches and analyzes information",
model_client=model_client,
tools=[tools.google_search_tool, tools.fetch_webpage_tool],
system_message="""You are a research assistant focused on finding accurate information.
Use the google_search tool to find relevant information.
Break down complex queries into specific search terms.
Always verify information across multiple sources when possible.
When you find relevant information, explain why it's relevant and how it connects to the query. When you get feedback from the a verifier agent, use your tools to act on the feedback and make progress.""",
)
verifier = AssistantAgent(
name="verifier",
description="A verification specialist who ensures research quality and completeness",
model_client=model_client,
system_message="""You are a research verification specialist.
Your role is to:
1. Verify that search queries are effective and suggest improvements if needed
2. Explore drill downs where needed e.g, if the answer is likely in a link in the returned search results, suggest clicking on the link
3. Suggest additional angles or perspectives to explore. Be judicious in suggesting new paths to avoid scope creep or wasting resources, if the task appears to be addressed and we can provide a report, do this and respond with "TERMINATE".
4. Track progress toward answering the original question
5. When the research is complete, provide a detailed summary in markdown format. For incomplete research, end your message with "CONTINUE RESEARCH". For complete research, end your message with APPROVED.
Your responses should be structured as:
- Progress Assessment
- Gaps/Issues (if any)
- Suggestions (if needed)
- Next Steps or Final Summary""",
)
summary_agent = AssistantAgent(
name="summary_agent",
description="A summary agent that provides a detailed markdown summary of the research as a report to the user.",
model_client=model_client,
Add Token Streaming in AGS , Support Env variables (#5659) <!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> This PR has 3 main improvements. - Token streaming - Adds support for environment variables in the app settings - Updates AGS to persist Gallery entry in db. ## Adds Token Streaming in AGS. Agentchat now supports streaming of tokens via `ModelClientStreamingChunkEvent `. This PR is to track progress on supporting that in the AutoGen Studio UI. If `model_client_stream` is enabled in an assitant agent, then token will be streamed in UI. ```python streaming_assistant = AssistantAgent( name="assistant", model_client=model_client, system_message="You are a helpful assistant.", model_client_stream=True, # Enable streaming tokens. ) ``` https://github.com/user-attachments/assets/74d43d78-6359-40c3-a78e-c84dcb5e02a1 ## Env Variables Also adds support for env variables in AGS Settings You can set env variables that are loaded just before a team is run. Handy to set variable to be used by tools etc. <img width="1291" alt="image" src="https://github.com/user-attachments/assets/437b9d90-ccee-42f7-be5d-94ab191afd67" /> > Note: the set variables are available to the server process. <!-- 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 #1234" --> Closes #5627 Closes #5662 Closes #5619 ## 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.
2025-02-25 07:21:08 -08:00
system_message="""You are a summary agent. Your role is to provide a detailed markdown summary of the research as a report to the user. Your report should have a reasonable title that matches the research question and should summarize the key details in the results found in natural an actionable manner. The main results/answer should be in the first paragraph. Where reasonable, your report should have clear comparison tables that drive critical insights. Most importantly, you should have a reference section and cite the key sources (where available) for facts obtained INSIDE THE MAIN REPORT. Also, where appropriate, you may add images if available that illustrate concepts needed for the summary.
2025-02-07 15:37:44 -08:00
Your report should end with the word "TERMINATE" to signal the end of the conversation.""",
)
termination = TextMentionTermination("TERMINATE") | MaxMessageTermination(max_messages=30)
selector_prompt = """You are coordinating a research team by selecting the team member to speak/act next. The following team member roles are available:
{roles}.
The research_assistant performs searches and analyzes information.
The verifier evaluates progress and ensures completeness.
The summary_agent provides a detailed markdown summary of the research as a report to the user.
Given the current context, select the most appropriate next speaker.
The research_assistant should search and analyze.
The verifier should evaluate progress and guide the research (select this role is there is a need to verify/evaluate progress). You should ONLY select the summary_agent role if the research is complete and it is time to generate a report.
Base your selection on:
1. Current stage of research
2. Last speaker's findings or suggestions
3. Need for verification vs need for new information
Read the following conversation. Then select the next role from {participants} to play. Only return the role.
{history}
Read the above conversation. Then select the next role from {participants} to play. ONLY RETURN THE ROLE."""
deep_research_team = SelectorGroupChat(
participants=[research_assistant, verifier, summary_agent],
model_client=model_client,
termination_condition=termination,
selector_prompt=selector_prompt,
allow_repeated_speaker=True,
)
builder.add_team(
deep_research_team.dump_component(),
label="Deep Research Team",
Enable LLM Call Observability in AGS (#5457) <!-- 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. --> It is often helpful to inspect the raw request and response to/from an LLM as agents act. This PR, does the following: - Updates TeamManager to yield LLMCallEvents from core library - Run in an async background task to listen for LLMCallEvent JIT style when a team is run - Add events to an async queue and - yield those events in addition to whatever actual agentchat team.run_stream yields. - Update the AGS UI to show those LLMCallEvents in the messages section as a team runs - Add settings panel to show/hide llm call events in messages. - Minor updates to default team <img width="1539" alt="image" src="https://github.com/user-attachments/assets/bfbb19fe-3560-4faa-b600-7dd244e0e974" /> <img width="1554" alt="image" src="https://github.com/user-attachments/assets/775624f5-ba83-46e8-81ff-512bfeed6bab" /> <img width="1538" alt="image" src="https://github.com/user-attachments/assets/3becbf85-b75a-4506-adb7-e5575ebbaec4" /> ## Why are these changes needed? <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #5440 ## Checks - [ ] I've included any doc changes needed for https://microsoft.github.io/autogen/. See https://microsoft.github.io/autogen/docs/Contribute#documentation 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.
2025-02-08 20:50:12 -08:00
description="A team with 3 agents - a Research Assistant that performs web searches and analyzes information, a Verifier that ensures research quality and completeness, and a Summary Agent that provides a detailed markdown summary of the research as a report to the user.",
2025-02-07 15:37:44 -08:00
)
return builder.build()
if __name__ == "__main__":
# Create and save the gallery
gallery = create_default_gallery()
# Save to file
with open("gallery_default.json", "w") as f:
f.write(gallery.model_dump_json(indent=2))