Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.agentfront.dev/llms.txt

Use this file to discover all available pages before exploring further.

Class Hierarchy

ExecutionContextBase<Out>
├── ToolContext<InSchema, OutSchema, In, Out>
├── ResourceContext<Params, Out>
├── AgentContext<InSchema, OutSchema, In, Out>
├── JobContext<InSchema, OutSchema, In, Out>
├── SkillContext
└── ChannelContext

PromptContext (independent, similar interface)

Common Features

All context classes provide:

Dependency Injection

// Required dependency (throws if not found)
const service = this.get(ServiceToken);

// Optional dependency (returns undefined if not found)
const optional = this.tryGet(OptionalToken);

Scope Access

// Access registries
const tools = this.scope.tools;
const resources = this.scope.resources;
const prompts = this.scope.prompts;
const agents = this.scope.agents;
const skills = this.scope.skills;
const jobs = this.scope.jobs;
const workflows = this.scope.workflows;

Logging

this.logger.debug('Debug message');
this.logger.info('Info message');
this.logger.warn('Warning message');
this.logger.error('Error message');

Authentication

For ExecutionContextBase-derived contexts (Tool, Resource, Agent, Skill, Job, Channel) read auth from the request context:
// Partial<AuthInfo> — preferred
const authInfo = this.context.authInfo;       // throws if no request context
const sessionId = authInfo?.sessionId;
const token = authInfo?.token;

// Typed FrontMcpAuthContext (roles / permissions / claims):
if (this.auth.hasRole('admin')) {
  const tenantId = this.auth.claims['tenantId'];
}
PromptContext does not extend ExecutionContextBase and exposes authInfo directly:
// In a class that extends PromptContext
const sessionId = this.authInfo.sessionId;
const token = this.authInfo.token;

Execution Tracking

// Mark current stage (for debugging/profiling)
this.mark('processing');
this.mark('complete');

Error Handling

// Fail execution with error
this.fail(new Error('Something went wrong'));

// Access current error
const error = this.error;

Context-Specific Features

ToolContext

Notifications, progress, elicitation, platform detection

ResourceContext

URI handling, parameter extraction

PromptContext

Argument handling, prompt building

AgentContext

LLM completion, tool execution, agent loop

SkillContext

Instruction loading, skill building

JobContext

Logging, progress, retry tracking

ChannelContext

Server→client notifications, broadcasts

ExecutionContextBase

Base class with shared functionality

Context Extensions

Plugins can extend all context classes with custom properties:
// In RememberPlugin
@Plugin({
  name: 'remember',
  contextExtensions: [
    { property: 'remember', token: RememberAccessorToken },
  ],
})
export class RememberPlugin {}

// In any context
class MyTool extends ToolContext {
  async execute(input) {
    // Access extended property
    await this.remember.set('key', 'value');
    const value = await this.remember.get('key');
  }
}

Request Context

Contexts that extend ExecutionContextBase (Tool, Resource, Agent, Skill, Job, Channel) can access the unified request context. PromptContext does NOT extend ExecutionContextBase and does not expose this.context or this.fetch() — it only carries args, metadata, runId, authInfo, scope, plus get/tryGet for DI.
// Get request context (throws if not available)
const ctx = this.context;

// Properties available
ctx.requestId;    // Unique request ID
ctx.sessionId;    // Session ID
ctx.scopeId;      // Scope ID
ctx.timestamp;    // Request timestamp
ctx.traceContext; // W3C trace context
ctx.metadata;     // Request metadata

// Context-scoped storage
ctx.set('myKey', 'myValue');
const value = ctx.get('myKey');

// Timing
ctx.mark('checkpoint1');
const elapsed = ctx.elapsed('checkpoint1');

HTTP Fetch

Contexts that extend ExecutionContextBase provide a context-aware fetch() (not available on PromptContext):
async execute(input) {
  // Auto-injects auth headers, trace context
  const response = await this.fetch('https://api.example.com/data', {
    method: 'POST',
    body: JSON.stringify(input),
  });

  return response.json();
}

Configuration Access

When ConfigPlugin is installed:
async execute(input) {
  // Typed access to environment variables
  const apiKey = this.config.get('API_KEY');
  const port = this.config.getNumber('PORT', 3000);
  const debug = this.config.getBoolean('DEBUG', false);
}

Best Practices

Let the Decorator Infer Types

The @Tool decorator infers input/output types from the schema — extend ToolContext without generics and let TypeScript do the rest.
@Tool({
  name: 'my_tool',
  inputSchema: { x: z.number() },
  outputSchema: z.object({ result: z.number() }),
})
class MyTool extends ToolContext {
  async execute(input: { x: number }): Promise<{ result: number }> {
    return { result: input.x * 2 };
  }
}

Handle Errors Gracefully

async execute(input) {
  try {
    const result = await this.get(ServiceToken).process(input);
    return result;
  } catch (error) {
    this.logger.error('Processing failed', { error });
    this.fail(new ToolExecutionError('my_tool', error));
  }
}

Use Stage Markers

async execute(input) {
  this.mark('validation');
  await this.validate(input);

  this.mark('processing');
  const result = await this.process(input);

  this.mark('complete');
  return result;
}

Leverage Platform Detection

async execute(input) {
  const result = await this.process(input);

  // Format differently based on platform
  if (this.platform === 'claude') {
    return formatForClaude(result);
  } else if (this.platform === 'openai') {
    return formatForOpenAI(result);
  }

  return result;
}