Skip to content

feat(schema): add max_tokens field to AgentDef for per-agent override #470

Description

@nskun

Summary

AgentDef has no max_tokens field. The fallback logic in agent_builder.py already exists:

agent_max_tokens = getattr(agent, "max_tokens", None)
max_tokens = agent_max_tokens if agent_max_tokens is not None else default_max_tokens

But since AgentDef uses extra="forbid" and has no max_tokens field, specifying it in YAML causes a validation error, and getattr always returns None.

Use Case

In multi-agent workflows, different agents have different output length requirements:

・Creator agents: need large max_tokens(e.g. 32768) to generate long artifacts.
・Reviewer agents: only produce short reviews, a smaller max_tokens (e.g. 8192) suffices and reduces cost.

Proposal

Add max_tokens to AgentDef in schema.py

max_tokens: int | None = None

This enables per-agent configuration in YAML:

agents:
  - name: creator
    max_tokens: 32768
    prompt: !file prompt_creator.md
  - name: reviewer
    max_tokens: 8192
    prompt: !file prompt_reviewer.md

No logic change needed -- the fallback in agent_builder.py already handles it. Default behavior is unchanged (omitted -> inherits runtime.max_tokens).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions