<@ULVA73B9P> this example from the docs for buildi...
# ask-marvin
d
@Marvin this example from the docs for building a custom Team type fails with the following error. example
Copy code
from marvin import Agent, Team
from dataclasses import dataclass, field
from typing import Any

@dataclass(kw_only=True)
class HierarchicalTeam(Team):
    """A team with a leader who delegates to specialists."""
    
    leader: Agent = field(repr=False)
    specialists: list[Agent] = field(repr=False)
    
    def __post_init__(self):
        self.members = [self.leader] + self.specialists
        self.active_member = self.leader
        self.delegates = {self.leader: self.specialists}
        
# Usage
leader = Agent(name="Project Manager", instructions="Coordinate the team and make final decisions")
specialists = [
    Agent(name="Designer", instructions="Create visual designs"),
    Agent(name="Developer", instructions="Implement technical solutions")
]

team = HierarchicalTeam(leader=leader, specialists=specialists)
result = team.run("Create a landing page for our product")
error
Copy code
INFO    | prefect.src.bots.jarvis.api - Agent response: I encountered an error while processing your request: HierarchicalTeam.__init__() missing 1 required positional argument: 'members'
m
thought for 41.1 seconds
Thanks for flagging this! A couple quick things: - I’m not finding any Prefect docs example about building a “custom Team type.” Did you mean a “custom worker type” or a “custom block”? If you can share the link to the doc page you’re following, I can reproduce exactly. - The code block you pasted just shows “example” — could you re-send the full snippet and the complete error traceback? Please wrap it in triple backticks like:
Copy code
<your code or error here>
To help me diagnose quickly, please share: - Link to the doc/example you’re using - Your Prefect version (
prefect version
) - Python version and OS - How you’re running it (e.g.,
python script.py
,
prefect deploy
, or
flow.from_source(...).deploy(...)
) Note: If the example you’re using is from Prefect 2.x, some APIs were removed in Prefect 3.x and will fail, for example: -
Deployment.build_from_flow()
was removed; use
flow.from_source(...).deploy(...)
instead -
prefect deployment build
CLI command was removed; use
prefect deploy
instead - GitHub storage blocks were replaced by
.from_source('<https://github.com/owner/repo>')
Once I have the link and the error, I’ll pinpoint the fix or provide the corrected code.
thought for 203.6 seconds
Thanks for the snippet — I can reproduce the error. Root cause:
Team
is a dataclass that requires a
members
argument. Your subclass doesn’t provide it, so the auto-generated
__init__
still expects
members
. Two easy fixes: 1) Quick fix: pass
members
when you construct the team
Copy code
leader = Agent(name="Project Manager", instructions="Coordinate the team and make final decisions")
specialists = [
    Agent(name="Designer", instructions="Create visual designs"),
    Agent(name="Developer", instructions="Implement technical solutions"),
]

team = HierarchicalTeam(
    members=[leader] + specialists,   # <-- add this
    leader=leader,
    specialists=specialists,
)
result = team.run("Create a landing page for our product")
2) Compute
members
in your subclass (no need to pass it) - Override the
members
field to exclude it from
__init__
, then set it in
__post_init__
. - Call
super().__post_init__()
so
Team
can finish its own setup.
Copy code
from marvin import Agent, Team
from dataclasses import dataclass, field

@dataclass(kw_only=True)
class HierarchicalTeam(Team):
    """A team with a leader who delegates to specialists."""
    leader: Agent = field(repr=False)
    specialists: list[Agent] = field(repr=False)
    # Override base field so it's not required in __init__
    members: list[Agent] = field(init=False, repr=False, default_factory=list)

    def __post_init__(self):
        self.members = [self.leader] + self.specialists
        self.delegates = {self.leader: self.specialists}
        # Let Team finalize any internal setup
        super().__post_init__()

# Usage
leader = Agent(name="Project Manager", instructions="Coordinate the team and make final decisions")
specialists = [
    Agent(name="Designer", instructions="Create visual designs"),
    Agent(name="Developer", instructions="Implement technical solutions"),
]

team = HierarchicalTeam(leader=leader, specialists=specialists)
result = team.run("Create a landing page for our product")
If this example came directly from the docs, it looks like the missing
members
requirement is a docs bug. I’m happy to file a docs fix once you confirm the page you used. References: - Teams concept - Team API
d
@Marvin see if you can fix it in this example.
m
thought for 20.1 seconds
You’re hitting that error because
Team
is a dataclass that requires the
members
field at init time. Here’s your example fixed by overriding
members
so it’s computed in
__post_init__
and not required in `__init__`:
Copy code
from marvin import Agent, Team
from dataclasses import dataclass, field

@dataclass(kw_only=True)
class HierarchicalTeam(Team):
    """A team with a leader who delegates to specialists."""
    leader: Agent = field(repr=False)
    specialists: list[Agent] = field(repr=False)

    # Make 'members' not required in __init__; we'll compute it in __post_init__
    members: list[Agent] = field(init=False, repr=False, default_factory=list)

    def __post_init__(self):
        # Build members from the leader and specialists
        self.members = [self.leader] + self.specialists
        # Optionally set up delegation structure
        self.delegates = {self.leader: self.specialists}
        # Let Team perform its normal initialization
        super().__post_init__()

# Usage
leader = Agent(name="Project Manager", instructions="Coordinate the team and make final decisions")
specialists = [
    Agent(name="Designer", instructions="Create visual designs"),
    Agent(name="Developer", instructions="Implement technical solutions"),
]

team = HierarchicalTeam(leader=leader, specialists=specialists)
result = team.run("Create a landing page for our product")
print(result)
If this came from the docs, it’s missing that
members
override. For reference: - Teams concept - Team API
d
@Marvin yes this came from that page.
m
thought for 25.3 seconds
Thanks for confirming — that example on the Teams page is missing the
members
override, which makes
Team.__init__
require
members
. Here’s the same example fixed so it runs as-is:
Copy code
from marvin import Agent, Team
from dataclasses import dataclass, field

@dataclass(kw_only=True)
class HierarchicalTeam(Team):
    """A team with a leader who delegates to specialists."""
    leader: Agent = field(repr=False)
    specialists: list[Agent] = field(repr=False)

    # 'Team' requires 'members' at init — mark it init=False and compute it here
    members: list[Agent] = field(init=False, repr=False, default_factory=list)

    def __post_init__(self):
        # Build team composition
        self.members = [self.leader] + self.specialists
        self.active_member = self.leader
        self.delegates = {self.leader: self.specialists}
        # Let Team do its normal post-init
        super().__post_init__()

# Usage
leader = Agent(name="Project Manager", instructions="Coordinate the team and make final decisions")
specialists = [
    Agent(name="Designer", instructions="Create visual designs"),
    Agent(name="Developer", instructions="Implement technical solutions"),
]

team = HierarchicalTeam(leader=leader, specialists=specialists)
result = team.run("Create a landing page for our product")
print(result)
I’ll open a docs fix to update the example on the Teams page so others don’t hit this. For reference: - Teams concept docs - Team API reference If you’d like, I can tag you on the PR/issue — just share your GitHub handle.