include_callback_events failed on AgentExecutor #97

Open
opened 2026-02-16 00:18:46 -05:00 by yindo · 4 comments
Owner

Originally created by @rever1and on GitHub (Jan 22, 2024).

I just find there are validation errors when I use AgentExecutor as the runnable.

I propose to add the the validation model for AgentStart and AgentFinish.

diff --git a/langserve/validation.py b/langserve/validation.py
index 7379bf6..b7aa4e7 100644
--- a/langserve/validation.py
+++ b/langserve/validation.py
@@ -26,6 +26,7 @@ from langchain.schema import (
     Generation,
     RunInfo,
 )
+from langchain_core.agents import AgentAction, AgentFinish
 from typing_extensions import Type
 
 from langserve.schema import BatchResponseMetadata, SingletonResponseMetadata
@@ -481,8 +482,32 @@ class OnRetrieverEnd(BaseModel):
     type: Literal["on_retriever_end"] = "on_retriever_end"
 
 
+class OnAgentAction(BaseModel):
+    """On Agent Action Callback Event"""
+
+    action: AgentAction
+    run_id: UUID
+    parent_run_id: Optional[UUID] = None
+    tags: Optional[List[str]] = None
+    kwargs: Any = None
+    type: Literal["on_agent_action"] = "on_agent_action"
+
+
+class OnAgentFinish(BaseModel):
+    """On Agent Finish Callback Event"""
+
+    finish: AgentFinish
+    run_id: UUID
+    parent_run_id: Optional[UUID] = None
+    tags: Optional[List[str]] = None
+    kwargs: Any = None
+    type: Literal["on_agent_finish"] = "on_agent_finish"
+
+
 class CallbackEvent(BaseModel):
     __root__: Union[
+        OnAgentAction,
+        OnAgentFinish,
         OnChainStart,
         OnChainEnd,
         OnChainError,
Originally created by @rever1and on GitHub (Jan 22, 2024). I just find there are validation errors when I use AgentExecutor as the runnable. I propose to add the the validation model for AgentStart and AgentFinish. ``` diff --git a/langserve/validation.py b/langserve/validation.py index 7379bf6..b7aa4e7 100644 --- a/langserve/validation.py +++ b/langserve/validation.py @@ -26,6 +26,7 @@ from langchain.schema import ( Generation, RunInfo, ) +from langchain_core.agents import AgentAction, AgentFinish from typing_extensions import Type from langserve.schema import BatchResponseMetadata, SingletonResponseMetadata @@ -481,8 +482,32 @@ class OnRetrieverEnd(BaseModel): type: Literal["on_retriever_end"] = "on_retriever_end" +class OnAgentAction(BaseModel): + """On Agent Action Callback Event""" + + action: AgentAction + run_id: UUID + parent_run_id: Optional[UUID] = None + tags: Optional[List[str]] = None + kwargs: Any = None + type: Literal["on_agent_action"] = "on_agent_action" + + +class OnAgentFinish(BaseModel): + """On Agent Finish Callback Event""" + + finish: AgentFinish + run_id: UUID + parent_run_id: Optional[UUID] = None + tags: Optional[List[str]] = None + kwargs: Any = None + type: Literal["on_agent_finish"] = "on_agent_finish" + + class CallbackEvent(BaseModel): __root__: Union[ + OnAgentAction, + OnAgentFinish, OnChainStart, OnChainEnd, OnChainError, ```
Author
Owner

@eyurtsev commented on GitHub (Jan 25, 2024):

Could you include a traceback? I haven't really advertised the callback API since it still has rough edges -- I'm 100% it doesn't handle all serialization cases.

This won't be prioritize for a while.

What are you using the callbacks for? We're likely going to expose the astream_events API first in LangServe to help stream agent responses

@eyurtsev commented on GitHub (Jan 25, 2024): Could you include a traceback? I haven't really advertised the callback API since it still has rough edges -- I'm 100% it doesn't handle all serialization cases. This won't be prioritize for a while. What are you using the callbacks for? We're likely going to expose the `astream_events` API first in LangServe to help stream agent responses
Author
Owner

@rever1and commented on GitHub (Jan 25, 2024):

Thanks for reply.

What are you using the callbacks for? We're likely going to expose the astream_events API first in LangServe to help stream agent responses

I'm trying to find a way to implement something like https://github.com/langchain-ai/streamlit-agent/blob/main/streamlit_agent/mrkl_demo.py. on the way, tried the callbacks

Could you include a traceback?

I'll try to next time if you prefer that.
Any instruction to provide a traceback safely? I worried that it may leak something sensitive for me.

This won't be prioritize for a while.

It ok for me.

@rever1and commented on GitHub (Jan 25, 2024): Thanks for reply. > What are you using the callbacks for? We're likely going to expose the astream_events API first in LangServe to help stream agent responses I'm trying to find a way to implement something like https://github.com/langchain-ai/streamlit-agent/blob/main/streamlit_agent/mrkl_demo.py. on the way, tried the callbacks > Could you include a traceback? I'll try to next time if you prefer that. Any instruction to provide a traceback safely? I worried that it may leak something sensitive for me. > This won't be prioritize for a while. It ok for me.
Author
Owner

@eyurtsev commented on GitHub (Feb 1, 2024):

Scan the traceback to see if there's any personal information there and wipe it out (usually it's just the user name on your machine).

Except for that there is usually no sensitive information in tracebacks

@eyurtsev commented on GitHub (Feb 1, 2024): Scan the traceback to see if there's any personal information there and wipe it out (usually it's just the user name on your machine). Except for that there is **usually** no sensitive information in tracebacks
Author
Owner

@eyurtsev commented on GitHub (Feb 1, 2024):

@rever1and try the astream events API now

See

https://python.langchain.com/docs/modules/agents/how_to/streaming#custom-streaming-with-events

@eyurtsev commented on GitHub (Feb 1, 2024): @rever1and try the astream events API now See https://python.langchain.com/docs/modules/agents/how_to/streaming#custom-streaming-with-events
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langserve#97