Agent name on Middleware #105

Closed
opened 2026-02-16 08:19:53 -05:00 by yindo · 2 comments
Owner

Originally created by @oscmejia on GitHub (Nov 4, 2025).

I s it possible to get each agent name of a middleware?
I'm setting name for each agent, and in the middleware using before_model and after_model, but only reciving information like the models name and token information.

any help will be apreciated.

Originally created by @oscmejia on GitHub (Nov 4, 2025). I s it possible to get each agent name of a middleware? I'm setting `name` for each agent, and in the middleware using `before_model` and `after_model`, but only reciving information like the models name and token information. any help will be apreciated.
yindo closed this issue 2026-02-16 08:19:53 -05:00
Author
Owner

@flingjie commented on GitHub (Nov 5, 2025):

What do you mean by “setting a name for each agent”?
If you’re referring to the sub-agent name, for example:

critique_sub_agent = {
    "name": "critique-agent",
    "description": "xxxx",
    "system_prompt": sub_critique_prompt,
}

You can actually see this name in the tool_calls field of the state during the before_model hook.

class LoggingMiddleware(AgentMiddleware):
    def before_model(self, state: AgentState, runtime: Runtime) -> dict[str, Any] | None:
        print(f"About to call model with {state}")
        return None
Image
@flingjie commented on GitHub (Nov 5, 2025): What do you mean by “setting a name for each agent”? If you’re referring to the **sub-agent name**, for example: ```python critique_sub_agent = { "name": "critique-agent", "description": "xxxx", "system_prompt": sub_critique_prompt, } ``` You can actually see this name in the `tool_calls` field of the `state` during the `before_model` hook. ``` class LoggingMiddleware(AgentMiddleware): def before_model(self, state: AgentState, runtime: Runtime) -> dict[str, Any] | None: print(f"About to call model with {state}") return None ``` <img width="1285" height="124" alt="Image" src="https://github.com/user-attachments/assets/489cea96-c360-4e23-9790-7942a0eb0bd2" />
Author
Owner

@oscmejia commented on GitHub (Nov 5, 2025):

thanks @flingjie
What I'm trying to do is create a middleware where wrap_model_call gets the name of the agent (main or nay subagent)

@oscmejia commented on GitHub (Nov 5, 2025): thanks @flingjie What I'm trying to do is create a middleware where `wrap_model_call` gets the name of the agent (main or nay subagent)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagents#105