MCPcopy
hub / github.com/lobehub/lobehub / Agent

Interface Agent

packages/agent-runtime/src/types/instruction.ts:69–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67 * It contains all the decision-making logic and is completely stateless.
68 */
69export interface Agent {
70 /**
71 * Calculate cost from usage statistics
72 * @param context - Cost calculation context with usage and limits
73 * @returns Updated cost information
74 */
75 calculateCost?: (context: CostCalculationContext) => Cost;
76
77 /**
78 * Calculate usage statistics from operation results
79 * @param operationType - Type of operation that was performed
80 * @param operationResult - Result data from the operation
81 * @param previousUsage - Previous usage statistics
82 * @returns Updated usage statistics
83 */
84 calculateUsage?: (
85 operationType: 'llm' | 'tool' | 'human_interaction',
86 operationResult: any,
87 previousUsage: Usage,
88 ) => Usage;
89
90 /** Optional custom executors mapping to extend runtime behaviors */
91 executors?: Partial<Record<AgentInstruction['type'], any>>;
92
93 /**
94 * Model runtime function for LLM calls - Agent owns its model integration
95 * @param payload - LLM call payload (messages, tools, etc.)
96 * @returns Async iterable of streaming response chunks
97 */
98 modelRuntime?: (payload: unknown) => AsyncIterable<any>;
99
100 /**
101 * The core runner method. Based on the current execution context and state,
102 * it decides what the next action should be.
103 * @param context - Current runtime context with phase and payload
104 * @param state - Complete agent state for reference
105 */
106 runner: (
107 context: AgentRuntimeContext,
108 state: AgentState,
109 ) => Promise<AgentInstruction | AgentInstruction[]>;
110
111 /** Optional tools registry held by the agent */
112 tools?: ToolRegistry;
113}
114
115// ── Payloads ──────────────────────────────────────────────
116

Callers

nothing calls this directly

Implementers 15

MockAgentpackages/agent-runtime/src/core/__test
CostTrackingAgentpackages/agent-runtime/src/core/__test
BatchToolAgentpackages/agent-runtime/src/core/__test
BlockedToolAgentpackages/agent-runtime/src/core/__test
ThoughtSignatureAgentpackages/agent-runtime/src/core/__test
ArrayReturnAgentpackages/agent-runtime/src/core/__test
BlockingAgentpackages/agent-runtime/src/core/__test
UsageTrackingAgentpackages/agent-runtime/src/core/__test
MultiRoundBatchAgentpackages/agent-runtime/src/core/__test
TwoBatchAgentpackages/agent-runtime/src/core/__test
WarnCostAgentpackages/agent-runtime/src/core/__test
ToolCostAgentpackages/agent-runtime/src/core/__test

Calls

no outgoing calls

Tested by

no test coverage detected