Skip to content

[FEATURE] Replace kwargs with explicit invocation_args parameter in Agent APIs #919

@zastrowm

Description

@zastrowm

Problem Statement

The current Agent APIs (Agent.__call__, Agent.invoke_async, Agent.stream_async) accept arbitrary keyword arguments via **kwargs, which are then converted to invocation_state and passed through the execution pipeline to tools. This has the downside that any new parameter we want to add to these methods could potentially conflict with user-provided kwargs, making it impossible to evolve the API without breaking changes.

Proposed Solution

Replace **kwargs with an explicit invocation_state parameter:

from typing import Optional, Dict, Any

# New API
def __call__(
    self, 
    prompt: AgentInput = None, 
    *, 
    invocation_state: dict | None  = None
) -> AgentResult:

async def invoke_async(
    self, 
    prompt: AgentInput = None, 
    *, 
    invocation_state: dict | None  = None
) -> AgentResult:

async def stream_async(
    self, 
    prompt: AgentInput = None, 
    *, 
    invocation_state: dict | None  = None
) -> AsyncIterator[Any]:

To allow for incremental adoption, I'd propose:

  • For 1.X we emit a warning to notify consumers of the future change
  • For 1.Y we accept both, preferring invocation_args if it's present
  • For 2.0, we only accept invocation_args

Use Case

Primarily to enable API evolution without breaking changes and make it explicit to callers what the invocation_state parameters are used throughout the code base.

Alternatives Solutions

No response

Additional Context

No response

Metadata

Metadata

Assignees

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