Skip to main content

useAmp Hook

Runs the same execution pipeline as <Amp>, but returns state for custom rendering. The source of truth is the Smithers DB (agents table).
import { useAmp } from "smithers-orchestrator";

function AmpPanel() {
  const { status, result, error, mode } = useAmp({
    mode: "smart",
    children: "Refactor the module for clarity.",
  });

  return (
    <panel>
      <text>Mode: {mode}</text>
      <text>Status: {status}</text>
      {error && <text>Error: {error.message}</text>}
      {result && <text>Output: {result.output}</text>}
    </panel>
  );
}

API

function useAmp(props: AmpProps): UseAmpResult

interface UseAmpResult {
  status: "pending" | "running" | "complete" | "error"
  agentId: string | null
  executionId: string | null
  mode: string
  result: AgentResult | null
  error: Error | null
  tailLog: TailLogEntry[]
}

Props

PropTypeDefaultDescription
childrenReactNodeThe prompt to send to Amp
mode'smart' | 'rush''smart'smart uses SOTA models; rush is faster/cheaper for small tasks
maxTurnsnumberMaximum number of agentic loops
systemPromptstringSystem prompt for the agent
permissionMode'default' | 'acceptEdits' | 'bypassPermissions''default'Permission mode for file operations
timeoutnumberTimeout in milliseconds
cwdstringWorking directory for the agent
continueThreadbooleanContinue from previous thread
resumeThreadstringResume a specific thread by ID
labelsstring[]Labels to attach to the thread
validate(result: AgentResult) => boolean | Promise<boolean>Validate result before accepting
retryOnValidationFailurebooleanRetry if validation fails
maxRetriesnumber3Maximum retry attempts
stopConditionsStopCondition[]Conditions that will stop the agent
middlewareSmithersMiddleware[]Middleware applied to this execution
tailLogCountnumber10Number of tail log entries to display during execution
tailLogLinesnumber10Number of lines to show per tail log entry
reportingEnabledbooleantrueEnable database reporting for this agent
recordStreamEventsbooleantrue when reportingEnabledRecord stream events to the database
onFinished(result: AgentResult) => voidCalled when agent finishes successfully
onError(error: Error) => voidCalled when agent encounters an error
onProgress(message: string) => voidCalled for progress updates
onToolCall(tool: string, input: any) => voidCalled when agent makes a tool call
onStreamPart(part: SmithersStreamPart) => voidCalled for typed stream events (when enabled)

Notes

  • Requires SmithersProvider context.
  • Respects ExecutionScope and executionEnabled.
  • tailLog is in-memory; status/result come from the DB.