-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement CustomData for agents; select agent in app (#77)
- Loading branch information
1 parent
cb450b5
commit acebd43
Showing
4 changed files
with
55 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing import Any | ||
|
||
from langchain_core.callbacks import adispatch_custom_event | ||
from langchain_core.messages import ChatMessage | ||
from langchain_core.runnables import RunnableConfig | ||
from langchain_core.runnables.config import merge_configs | ||
from pydantic import BaseModel, Field | ||
|
||
|
||
class CustomData(BaseModel): | ||
"Custom data being sent by an agent" | ||
|
||
type: str = Field( | ||
description="The type of custom data, used in dispatch events", | ||
default="custom_data", | ||
) | ||
data: dict[str, Any] = Field(description="The custom data") | ||
|
||
def to_langchain(self) -> ChatMessage: | ||
return ChatMessage(content=[self.data], role="custom") | ||
|
||
async def adispatch(self, config: RunnableConfig | None = None) -> None: | ||
dispatch_config = RunnableConfig( | ||
tags=["custom_data_dispatch"], | ||
) | ||
await adispatch_custom_event( | ||
name=self.type, | ||
data=self.to_langchain(), | ||
config=merge_configs(config, dispatch_config), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters