import { a as AiContextParams } from '../ai-context-2768aadc.js'; import { Message as Message$1 } from '@vn-sdk/runtime-client-gql'; import { Message } from '@vn-sdk/shared'; import '../types/frontend-action.js'; import 'react'; import './use-tree.js'; import '../types/document-pointer.js'; import '../types/chat-suggestion-configuration.js'; import '../types/ai-agent-action.js'; import '../types/ai-agent-state.js'; /** * * Usage of this hook assumes some additional setup in your application, for more information * on that see the CoAgents [getting started guide](/coagents/quickstart/langgraph). * * * CoAgents demonstration * * * This hook is used to integrate an agent into your application. With its use, you can * render and update the state of an agent, allowing for a dynamic and interactive experience. * We call these shared state experiences agentic copilots, or CoAgents for short. * * ## Usage * * ### Simple Usage * * ```tsx * import { useAiAgent } from "@vn-sdk/react-core"; * * type AgentState = { * count: number; * } * * const agent = useAiAgent({ * name: "my-agent", * initialState: { * count: 0, * }, * }); * * ``` * * `useAiAgent` returns an object with the following properties: * * ```tsx * const { * name, // The name of the agent currently being used. * nodeName, // The name of the current LangGraph node. * state, // The current state of the agent. * setState, // A function to update the state of the agent. * running, // A boolean indicating if the agent is currently running. * start, // A function to start the agent. * stop, // A function to stop the agent. * run, // A function to re-run the agent. Takes a HintFunction to inform the agent why it is being re-run. * } = agent; * ``` * * Finally we can leverage these properties to create reactive experiences with the agent! * * ```tsx * const { state, setState } = useAiAgent({ * name: "my-agent", * initialState: { * count: 0, * }, * }); * * return ( *
*

Count: {state.count}

* *
* ); * ``` * * This reactivity is bidirectional, meaning that changes to the state from the agent will be reflected in the UI and vice versa. * * ## Parameters * * The options to use when creating the coagent. * * The name of the agent to use. * * * The initial state of the agent. * * * State to manage externally if you are using this hook with external state management. * * * A function to update the state of the agent if you are using this hook with external state management. * * */ interface UseCoagentOptionsBase { /** * The name of the agent being used. */ name: string; /** * @deprecated - use "config.configurable" * Config to pass to a LangGraph Agent */ configurable?: Record; /** * Config to pass to a LangGraph Agent */ config?: { configurable?: Record; [key: string]: any; }; } interface WithInternalStateManagementAndInitial extends UseCoagentOptionsBase { /** * The initial state of the agent. */ initialState: T; } interface WithInternalStateManagement extends UseCoagentOptionsBase { /** * Optional initialState with default type any */ initialState?: any; } interface WithExternalStateManagement extends UseCoagentOptionsBase { /** * The current state of the agent. */ state: T; /** * A function to update the state of the agent. */ setState: (newState: T | ((prevState: T | undefined) => T)) => void; } type UseCoagentOptions = WithInternalStateManagementAndInitial | WithInternalStateManagement | WithExternalStateManagement; interface UseCoagentReturnType { /** * The name of the agent being used. */ name: string; /** * The name of the current LangGraph node. */ nodeName?: string; /** * The ID of the thread the agent is running in. */ threadId?: string; /** * A boolean indicating if the agent is currently running. */ running: boolean; /** * The current state of the agent. */ state: T; /** * A function to update the state of the agent. */ setState: (newState: T | ((prevState: T | undefined) => T)) => void; /** * A function to start the agent. */ start: () => void; /** * A function to stop the agent. */ stop: () => void; /** * A function to re-run the agent. The hint function can be used to provide a hint to the agent * about why it is being re-run again. */ run: (hint?: HintFunction) => Promise; } interface HintFunctionParams { /** * The previous state of the agent. */ previousState: any; /** * The current state of the agent. */ currentState: any; } type HintFunction = (params: HintFunctionParams) => Message | undefined; /** * This hook is used to integrate an agent into your application. With its use, you can * render and update the state of the agent, allowing for a dynamic and interactive experience. * We call these shared state experiences "agentic copilots". To get started using agentic copilots, which * we refer to as CoAgents, checkout the documentation at https://docs.vn.ai/coagents/quickstart/langgraph. */ declare function useAiAgent(options: UseCoagentOptions): UseCoagentReturnType; declare function startAgent(name: string, context: AiContextParams): void; declare function stopAgent(name: string, context: AiContextParams): void; declare function runAgent(name: string, context: AiContextParams, messages: Message$1[], sendMessage: (message: Message) => Promise, runChatCompletion: () => Promise, hint?: HintFunction): Promise; export { HintFunction, HintFunctionParams, UseCoagentReturnType, runAgent, startAgent, stopAgent, useAiAgent };