@langchain/langgraph
Version:
LangGraph
51 lines (50 loc) • 2.35 kB
TypeScript
import { LanguageModelLike } from "@langchain/core/language_models/base";
import { AIMessage, BaseMessage, BaseMessageLike } from "@langchain/core/messages";
export type AgentNameMode = "inline";
/**
* Attach formatted agent names to the messages passed to and from a language model.
*
* This is useful for making a message history with multiple agents more coherent.
*
* NOTE: agent name is consumed from the message.name field.
* If you're using an agent built with createReactAgent, name is automatically set.
* If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.
*
* @param message - Message to add agent name formatting to
* @returns Message with agent name formatting
*
* @internal
*/
export declare function _addInlineAgentName<T extends BaseMessageLike>(message: T): T | AIMessage;
/**
* Remove explicit name and content XML tags from the AI message content.
*
* Examples:
*
* @example
* ```typescript
* removeInlineAgentName(new AIMessage({ content: "<name>assistant</name><content>Hello</content>", name: "assistant" }))
* // AIMessage with content: "Hello"
*
* removeInlineAgentName(new AIMessage({ content: [{type: "text", text: "<name>assistant</name><content>Hello</content>"}], name: "assistant" }))
* // AIMessage with content: [{type: "text", text: "Hello"}]
* ```
*
* @internal
*/
export declare function _removeInlineAgentName<T extends BaseMessage>(message: T): T;
/**
* Attach formatted agent names to the messages passed to and from a language model.
*
* This is useful for making a message history with multiple agents more coherent.
*
* NOTE: agent name is consumed from the message.name field.
* If you're using an agent built with createReactAgent, name is automatically set.
* If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.
*
* @param model - Language model to add agent name formatting to
* @param agentNameMode - How to expose the agent name to the LLM
* - "inline": Add the agent name directly into the content field of the AI message using XML-style tags.
* Example: "How can I help you" -> "<name>agent_name</name><content>How can I help you?</content>".
*/
export declare function withAgentName(model: LanguageModelLike, agentNameMode: AgentNameMode): LanguageModelLike;