Skip to content

Component Agent Runtime

Reese Hodge edited this page Sep 27, 2026 · 21 revisions

Component Agent Runtime

The agent runtime is a Node HTTP server around the Strands SDK. It creates a Max Height agent with a Bedrock model and three tools, exposes /ping and /invocations, tracks short-lived sessions in memory, and includes separate modules for memory extraction/storage, personality checking, stutter injection, re-engagement, observability spans, and golden personality evaluation data. It connects conceptually to Component-WebSocket-Transport and deployment resources in Component-Infra-Stacks.

Files

  • packages/agent/src/index.ts creates the Strands agent and HTTP server.
  • packages/agent/src/handlers/sessionManager.ts creates sessions and enforces caps.
  • packages/agent/src/handlers/reEngagement.ts schedules idle nudges.
  • packages/agent/src/handlers/personalityCheck.ts checks response text for voice and banned patterns.
  • packages/agent/src/handlers/observability.ts emits trace spans as JSON.
  • packages/agent/src/memory/* defines memory extraction, adapter, handlers, and a client abstraction.
  • packages/agent/src/personality/systemPrompt.ts builds the system prompt.
  • packages/agent/src/personality/stutterInjection.ts detects/injects stutters.
  • packages/agent/src/tools/* defines weather, news, and web-search tool schemas and fetchers.
  • packages/agent/src/evaluations/personality-gate.ts exports the golden-set evaluation configuration.
  • packages/agent/src/types/index.ts exports shared agent-side interfaces.

Exported functions and types

Runtime:

  • createMaxHeightAgent(options?: { displayAlias?: string })
  • __test = { sessions, requestHandler, handleInvocations }

Session handling:

  • type SessionState = 'GREETING' | 'ACTIVE' | 'IDLE' | 'WINDING_DOWN' | 'ENDED'
  • type EndReason = 'cap_reached' | 'user_left' | 'error' | 'manual'
  • createSession(params: { actorId: string; greetingId: string }): Session
  • checkSessionCaps(session: Session): SessionCapResult
  • endSession(session: Session, reason: EndReason): Session
  • getSessionState(session: Session): SessionState

Personality and stutter:

  • buildSystemPrompt(options?: SystemPromptOptions): string
  • checkPersonality(input: PersonalityCheckInput): PersonalityCheckResult
  • isStutter(text: string): boolean
  • countStutters(text: string): number
  • injectStutters(text: string, options: StutterOptions): StutterResult

Memory:

  • createMemoryAdapter(config: MemoryAdapterConfig): MemoryAdapter
  • extractMemories(turns: TurnContent[], sessionId: string): ExtractionResult
  • createAgentCoreMemoryClient(): AgentCoreMemoryClient
  • handleForgetMe(adapter, actorId), handleListMemories(adapter, actorId), handleDeleteMemory(adapter, memoryRecordId)

Tools:

  • newsToolSchema, fetchNews(input, fetchFn?)
  • weatherToolSchema, fetchWeather(input, fetchFn?)
  • webSearchToolSchema, fetchWebSearch(input, fetchFn?)

Observability and evaluation:

  • TRACE_SPANS
  • startSpan(name, attributes?), endSpan(name, additionalAttributes?), getActiveSpans(), setSpanEmitter(fn)
  • RUBRIC_DIMENSIONS, PASS_CRITERIA, AUTO_FAIL_RULES, TEST_CATEGORY_REQUIREMENTS, goldenTestCases

Runtime path

index.ts starts an HTTP listener on port 8080 unless running under tests. GET /ping returns a health JSON response. POST /invocations parses JSON containing optional message, displayAlias, sessionId, actorId, and greetingId.

For each invocation it:

  1. Starts a session.cold_start span.
  2. Gets or creates an in-memory Session.
  3. Enforces 50 turns, 20,000 estimated/reported tokens, and 30 minutes.
  4. Creates a Strands agent with the current display alias.
  5. Invokes the model with the message or Hello.
  6. Extracts text blocks from the result.
  7. Updates turn/token counts.
  8. Streams Server-Sent Events shaped as data: { type: 'text' | 'done' | 'error', ... }.

The agent factory uses a Bedrock model ID and maxTokens: 250, plus tools named get_news, get_weather, and web_search.

Memory behavior

Memory extraction is pattern-based. It can extract:

  • display alias from assistant name questions followed by user answers.
  • user facts.
  • preferences.
  • repeated or multi-turn topics.
  • summaries after at least five user turns.

createMemoryAdapter() namespaces records as /max-height/{actorId}/, retrieves top 10 records, stores records with batch create, lists records, deletes one record, and wipes all records for an actor. Retrieval failures degrade to an empty list.

Gotchas

  • warmBedrockClient() only constructs the agent — it never exercises the Bedrock client. The V2 snapshot therefore captures none of the endpoint resolution, service-model parsing or connection-pool setup that the warm-up exists to capture, and every restored instance re-pays it. The stated benefit of the readiness gate is currently unrealized. Tracked as T154; it is a Concept-Budget-Ceiling decision because a real round-trip costs tokens on every container start.
  • createAgentCoreMemoryClient() intentionally throws: AgentCore Memory client not configured.... Production memory requires a real client or dependency injection; tests can mock it.
  • Memory modules are exported, but index.ts does not retrieve memories, store extracted memories, or pass memory context into buildSystemPrompt().
  • checkPersonality() and injectStutters() exist but are not invoked in index.ts; current runtime relies on the system prompt and tools rather than a post-generation gate.
  • The agent server streams SSE over HTTP, while the frontend transport currently expects WebSocket message frames.

Clone this wiki locally