langserve
langserve copied to clipboard
include_callback_events failed on AgentExecutor
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,
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
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.
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
@rever1and try the astream events API now
See
https://python.langchain.com/docs/modules/agents/how_to/streaming#custom-streaming-with-events