Skip to content

before_agent_callback is not working as expected #1567

@jasveer-os

Description

@jasveer-os

A simple agent with defined 'before_agent_callback' which is returning 'None' is terminating the session.

Expected as per docs is that returning None should not bypass LLM and work as usual.

Code:

before_agent_callback:

def log_agent_timing(callback_context: CallbackContext) -> Optional[types.Content]:
    agent_name = callback_context.agent_name
    reqId = callback_context.state[REQUEST_ID]
    print(f"{reqId} [Callback] Before Agent call for agent: {agent_name}")
    events = callback_context.state["events"]
    events.append({"event-name": "before-agent-event", "time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "name": agent_name})
    callback_context.state["events"] = events
    return None

Let me know what else detail is required.

DETAILS
OS: Mac
ADK version: 1.3.0
Python version: 3.10

Metadata

Metadata

Assignees

Labels

bot triaged[Bot] This issue is triaged by ADK botcore[Component] This issue is related to the core interface and implementation

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions