langchain.js
    Preparing search index...

    Interface AgentMiddleware<TSchema, TContextSchema, TFullContext>

    Base middleware interface.

    interface AgentMiddleware<
        TSchema extends BaseMessage
        | undefined = undefined,
        TContextSchema extends
        
                | BaseMessage
                | BaseMessage<BaseMessage>
                | BaseMessage<BaseMessage>
                | undefined = undefined,
        TFullContext = any,
    > {
        afterModelJumpTo?: ("tools" | "model" | "end")[];
        beforeModelJumpTo?: ("tools" | "model" | "end")[];
        contextSchema?: TContextSchema;
        name: string;
        stateSchema?: TSchema;
        tools?: any[];
        afterModel?(
            state: (
                TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}
            ) & AgentBuiltInState,
            runtime: Runtime<TFullContext>,
        ): Promise<
            MiddlewareResult<
                Partial<
                    TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {},
                >,
            >,
        >;
        beforeModel?(
            state: (
                TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}
            ) & AgentBuiltInState,
            runtime: Runtime<TFullContext>,
        ): Promise<
            MiddlewareResult<
                Partial<
                    TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {},
                >,
            >,
        >;
        modifyModelRequest?(
            request: ModelRequest,
            state: (
                TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}
            ) & AgentBuiltInState,
            runtime: Runtime<TFullContext>,
        ): void | Partial<ModelRequest> | Promise<void | Partial<ModelRequest>>;
    }

    Type Parameters

    Index

    Properties

    afterModelJumpTo?: ("tools" | "model" | "end")[]
    beforeModelJumpTo?: ("tools" | "model" | "end")[]
    contextSchema?: TContextSchema
    name: string
    stateSchema?: TSchema
    tools?: any[]

    Methods

    • Parameters

      Returns Promise<
          MiddlewareResult<
              Partial<
                  TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {},
              >,
          >,
      >

    • Parameters

      Returns Promise<
          MiddlewareResult<
              Partial<
                  TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {},
              >,
          >,
      >

    • Runs before each LLM call, can modify call parameters, changes are not persistent e.g. if you change model, it will only be changed for the next model call

      Parameters

      • request: ModelRequest
      • state: (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState

        Current state (read-only in this phase)

      • runtime: Runtime<TFullContext>

        Runtime context and metadata

      Returns void | Partial<ModelRequest> | Promise<void | Partial<ModelRequest>>

      Modified options or undefined to pass through