| 67 | * It contains all the decision-making logic and is completely stateless. |
| 68 | */ |
| 69 | export 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 |
nothing calls this directly
no outgoing calls
no test coverage detected