CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-langchain--core

Core LangChain.js abstractions and schemas for building applications with Large Language Models

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

agents.mddocs/

Agents

Agent framework for autonomous task execution and tool usage. Agents can plan, execute actions, and make decisions based on observations from their environment.

Capabilities

Agent Actions and Steps

Core types for representing agent decision-making and execution.

/**
 * Action taken by an agent to use a tool
 */
interface AgentAction {
  /** Name of the tool to execute */
  tool: string;
  /** Input to provide to the tool */
  toolInput: string | Record<string, any>;
  /** Agent's reasoning log for this action */
  log: string;
}

/**
 * Final output when agent completes its task
 */
interface AgentFinish {
  /** Final return values from the agent */
  returnValues: Record<string, any>;
  /** Agent's final reasoning log */
  log: string;
}

/**
 * Single step in agent execution cycle
 */
interface AgentStep {
  /** Action that was taken */
  action: AgentAction;
  /** Observation result from the action */
  observation: string;
}

Usage Examples:

import { AgentAction, AgentFinish, AgentStep } from "@langchain/core/agents";

// Example agent action
const action: AgentAction = {
  tool: "calculator",
  toolInput: { operation: "multiply", a: 23, b: 7 },
  log: "I need to calculate 23 × 7 to solve this problem"
};

// Example agent step
const step: AgentStep = {
  action: action,
  observation: "The result of 23 × 7 is 161"
};

// Example agent finish
const finish: AgentFinish = {
  returnValues: { answer: "161", explanation: "The calculation gives us 161" },
  log: "I have successfully calculated the result and can provide the final answer"
};

Agent Planning

Types for agent planning and intermediate steps.

/**
 * Intermediate steps in agent execution
 */
type AgentSteps = AgentStep[];

/**
 * Plan generated by an agent
 */
interface AgentPlan {
  /** Planned actions */
  steps: AgentAction[];
  /** Reasoning for the plan */
  reasoning: string;
}

/**
 * Agent execution context
 */
interface AgentExecutorInput {
  /** Available tools */
  tools: StructuredToolInterface[];
  /** Agent instance */
  agent: BaseAgent;
  /** Maximum iterations allowed */
  maxIterations?: number;
  /** Early stopping method */
  earlyStoppingMethod?: "force" | "generate";
  /** Return intermediate steps */
  returnIntermediateSteps?: boolean;
}

Agent Types

Base Agent

/**
 * Abstract base class for agents
 */
abstract class BaseAgent {
  /** Available tools */
  tools: StructuredToolInterface[];
  
  constructor(input: { tools: StructuredToolInterface[] });
  
  /** Plan next action given input and previous steps */
  abstract plan(
    steps: AgentStep[],
    inputs: Record<string, any>,
    callbacks?: Callbacks
  ): Promise<AgentAction | AgentFinish>;
  
  /** Get allowed tools for this agent */
  abstract getAllowedTools(): string[] | undefined;
}

Single Action Agent

/**
 * Agent that takes one action at a time
 */
abstract class BaseSingleActionAgent extends BaseAgent {
  /** Plan single next action */
  abstract plan(
    steps: AgentStep[],
    inputs: Record<string, any>,
    callbacks?: Callbacks
  ): Promise<AgentAction | AgentFinish>;
}

Multi Action Agent

/**
 * Agent that can plan multiple actions
 */
abstract class BaseMultiActionAgent extends BaseAgent {
  /** Plan multiple next actions */
  abstract plan(
    steps: AgentStep[],
    inputs: Record<string, any>,
    callbacks?: Callbacks
  ): Promise<AgentAction[] | AgentFinish>;
}

Types

type AgentActionType = AgentAction | AgentAction[];

interface OutputParserArgs {
  /** Available tools */
  tools: StructuredToolInterface[];
  /** Instructions for tool usage */
  toolsInstructions?: string;
}

interface AgentArgs {
  outputParser: AgentActionOutputParser;
  allowedTools?: string[];
}

abstract class AgentActionOutputParser extends BaseOutputParser<AgentAction | AgentFinish> {
  abstract parse(text: string): Promise<AgentAction | AgentFinish>;
  getFormatInstructions(): string;
}

docs

agents.md

caches.md

callbacks.md

documents.md

embeddings.md

index.md

language-models.md

memory-storage.md

messages.md

output-parsers.md

prompts.md

retrievers.md

runnables.md

tools.md

vectorstores.md

tile.json