Skip to content

Python: [Bug]: BaseChatClient.as_agent() passes function_invocation_configuration to Agent() which doesn't accept it #5180

@Laende

Description

@Laende

Description

File: python/packages/core/agent_framework/_clients.pyBaseChatClient.as_agent()

Description:

BaseChatClient.as_agent() accepts a function_invocation_configuration parameter and forwards it into Agent(**agent_kwargs). However, Agent.__init__() (in _agents.py) does not accept this keyword argument, causing a TypeError at runtime whenever function_invocation_configuration is provided.

TypeError: Agent.__init__() got an unexpected keyword argument 'function_invocation_configuration'

Root cause:

function_invocation_configuration is consumed by FunctionInvocationLayer, which is in the client's MRO (OpenAIChatCompletionClientFunctionInvocationLayer → ...), not in the Agent's MRO (AgentAgentMiddlewareLayerAgentTelemetryLayerRawAgentBaseAgent → ...).

Lines 86-87 of as_agent() conditionally add it to agent_kwargs, and line 89 passes it to Agent():

if function_invocation_configuration is not None:
    agent_kwargs["function_invocation_configuration"] = function_invocation_configuration

return Agent(**agent_kwargs)

Since Agent.__init__ has no **kwargs and no function_invocation_configuration parameter, this always raises TypeError.

Reproduction:

from agent_framework import FunctionInvocationConfiguration
from agent_framework.openai import OpenAIChatCompletionClient

client = OpenAIChatCompletionClient(model="gpt-4o", api_key="test")

# This raises TypeError
agent = client.as_agent(
    name="test",
    instructions="You are helpful.",
    function_invocation_configuration=FunctionInvocationConfiguration(
        include_detailed_errors=True,
    ),
)

Expected behavior:

as_agent() should either apply function_invocation_configuration to the client before creating the Agent (since it's a client-level concern), or Agent.__init__ should accept and forward it appropriately.

Workaround:

Set function_invocation_configuration at client construction time instead:

client = OpenAIChatCompletionClient(
    model="gpt-4o",
    api_key="test",
    function_invocation_configuration=FunctionInvocationConfiguration(
        include_detailed_errors=True,
    ),
)
agent = client.as_agent(name="test", instructions="You are helpful.")

Code Sample

Error Messages / Stack Traces

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], [line 6](vscode-notebook-cell:?execution_count=3&line=6)
      2 from agent_framework.openai import OpenAIChatCompletionClient
      3 
      4 
      5 # This raises TypeError
----> [6](vscode-notebook-cell:?execution_count=3&line=6) agent = client.as_agent(
      7     name="test",
      8     instructions="You are helpful.",
      9     function_invocation_configuration=FunctionInvocationConfiguration(

File ...\agent_framework\_clients.py:652, in BaseChatClient.as_agent(self, id, name, description, instructions, tools, default_options, context_providers, middleware, require_per_service_call_history_persistence, function_invocation_configuration, compaction_strategy, tokenizer, additional_properties)
    649 if function_invocation_configuration is not None:
    650     agent_kwargs["function_invocation_configuration"] = function_invocation_configuration
--> [652](file:///.../agent_framework/_clients.py:652) return Agent(**agent_kwargs)

TypeError: Agent.__init__() got an unexpected keyword argument 'function_invocation_configuration'

Package Versions

agent-framework-core: 1.0.0

Python Version

Python 3.14

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions