Execution context for an AI agent, managing conversation history, cost tracking, and budgets.

const context = new AgentContext({
userId: 'user-123',
sessionId: 'session-abc',
environment: 'production',
metadata: { department: 'support' }
});

context.setBudget(1.00); // $1 max
context.addMessage({ role: 'user', content: 'Hello', timestamp: new Date() });
context.recordCost({ provider: 'openai', model: 'gpt-4', inputTokens: 100, outputTokens: 50, cost: 0.05 });

Constructors

  • Parameters

    • options: {
          userId?: string;
          sessionId: string;
          environment: "development" | "staging" | "production";
          metadata?: Record<string, unknown>;
      }

    Returns AgentContext

Methods

  • Gets the remaining budget

    Returns undefined | number

    The remaining budget, or undefined if no budget was set

Properties

userId?: string
sessionId: string
timestamp: Date
environment: "development" | "staging" | "production"
metadata: Record<string, unknown>