Skip to content

structured output with swarm/graph example #2293

@pradeepdev-1995

Description

@pradeepdev-1995

Problem Statement

form the official documentation the structured output is using like given format

from pydantic import BaseModel, Field
from strands import Agent

# 1) Define the Pydantic model
class PersonInfo(BaseModel):
    """Model that contains information about a Person"""
    name: str = Field(description="Name of the person")
    age: int = Field(description="Age of the person")
    occupation: str = Field(description="Occupation of the person")

# 2) Pass the model to the agent
agent = Agent()
result = agent(
    "John Smith is a 30 year-old software engineer",
    structured_output_model=PersonInfo
)

The structured_output_mode argument passes the Pydantic schema during the agent invocation time.

What is the corresponding method in the swarm pattern and the graph pattern? can we pass this argument while invoking a swarm/graph multi agent pattern?

swarm = Swarm(
    [coder, researcher, reviewer, architect],
    entry_point=researcher,  # Start with the researcher
)
result = swarm("Design and implement a simple REST API for a todo app",structured_output_model=PersonInfo)

Proposed Solution

No response

Use Case

form the official documentation the structured output is using like given format

from pydantic import BaseModel, Field
from strands import Agent

# 1) Define the Pydantic model
class PersonInfo(BaseModel):
    """Model that contains information about a Person"""
    name: str = Field(description="Name of the person")
    age: int = Field(description="Age of the person")
    occupation: str = Field(description="Occupation of the person")

# 2) Pass the model to the agent
agent = Agent()
result = agent(
    "John Smith is a 30 year-old software engineer",
    structured_output_model=PersonInfo
)

The structured_output_mode argument passes the Pydantic schema during the agent invocation time.

What is the corresponding method in the swarm pattern and the graph pattern? can we pass this argument while invoking a swarm/graph multi agent pattern?

swarm = Swarm(
    [coder, researcher, reviewer, architect],
    entry_point=researcher,  # Start with the researcher
)
result = swarm("Design and implement a simple REST API for a todo app",structured_output_model=PersonInfo)

Alternatives Solutions

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions