Assembly Strategies: assemble_context() Reference

Format character memories into structured prompt blocks optimized for different agent types.

Table of contents
  1. Overview
  2. Usage
    1. Python
    2. TypeScript
    3. Parameters
  3. Strategy: default
    1. Example output
  4. Strategy: conversational
    1. Example output
  5. Strategy: task_focused
    1. Example output
  6. Strategy: concierge
    1. Example output
  7. Strategy: matching
    1. Example output
  8. Token budget management
    1. Choosing a token budget
    2. Python example with budget control
    3. TypeScript example with budget control
  9. Combining strategies with memory modes
  10. Next steps

Overview

assemble_context() retrieves a character’s memories and formats them into a text block ready to inject into an LLM prompt. The strategy parameter controls the format and emphasis.

Strategy Optimized for Key emphasis
default General purpose Balanced profile + memories
conversational Chat agents Personality-forward, natural tone
task_focused Coding, task execution Structured sections, clear directives
concierge Customer service Customer context first, service-oriented
matching Compatibility, dating Trait-focused, comparison-friendly

Usage

Python

from hippodid import HippoDid

client = HippoDid(api_key="hd_key_...")

context = client.assemble_context(
    character_id="CHARACTER_ID",
    query="user asking about project architecture",
    strategy="task_focused",
    max_tokens=2000,
)

# Inject into your prompt
prompt = f"You are a coding assistant.\n\n{context.formatted_prompt}\n\nUser: {user_message}"

TypeScript

import { HippoDid } from "@hippodid/sdk";

const client = new HippoDid({ apiKey: "hd_key_..." });

const context = await client.assembleContext("CHARACTER_ID", "user asking about project architecture", {
  strategy: "task_focused",
  topK: 10,
});

const prompt = `You are a coding assistant.\n\n${context.formattedPrompt}\n\nUser: ${userMessage}`;

Parameters

Parameter Type Required Description
character_id string yes The character whose memories to assemble
query string no Search query to find relevant memories. If omitted, returns the most recent/salient memories.
strategy string no One of: default, conversational, task_focused, concierge, matching. Default: default.
max_tokens int no Token budget for the assembled context. Default: 2000.
categories string[] no Limit to specific memory categories.

Strategy: default

A balanced format that includes the character profile and relevant memories. Good for general-purpose agents.

Example output

## About This Character
Name: Project Alpha
Background: A full-stack web application using React and Spring Boot.

## Relevant Memories

### Preferences
- Uses TypeScript with strict mode enabled [salience: 0.85]
- Prefers functional components over class components [salience: 0.78]

### Decisions
- Chose PostgreSQL over MongoDB for relational data integrity [salience: 0.90]
- API versioning via URL path (/v1/, /v2/) not headers [salience: 0.72]

### Skills
- Team is proficient in React, Spring Boot, and PostgreSQL [salience: 0.65]

When to use: When you do not have a more specific need. Works well for developer assistants, general Q&A, and multi-purpose agents.


Strategy: conversational

Chat-optimized format that leads with personality and communication style. Memories are woven in naturally rather than listed.

Example output

You are talking with Jamie, a creative writer who enjoys wordplay and
prefers casual conversation. Jamie has a dry sense of humor and appreciates
when you match their tone.

Things you know about Jamie:
- Loves science fiction, especially Ursula K. Le Guin and Ted Chiang
- Currently working on a short story collection about AI consciousness
- Prefers brainstorming over outlines — likes to discover the story as they write
- Had a breakthrough last week on the theme of their second story
- Finds overly formal language off-putting

Recent context:
- Last session discussed character development for story #3
- Jamie mentioned they were stuck on the ending of story #1

When to use: Chat companions, creative writing assistants, therapy bots, any agent where personality and rapport matter more than structured information.


Strategy: task_focused

Structured format with clear sections optimized for agents that need to execute specific tasks. Includes directives, constraints, and relevant technical context.

Example output

# Character Context: Project Alpha

## Profile
- Type: Full-stack web application
- Stack: React + TypeScript (frontend), Spring Boot + Java 21 (backend)
- Database: PostgreSQL with pgvector

## Active Directives
- All new endpoints must include OpenAPI annotations
- Use Java Records for DTOs, not classes
- Test coverage required for all service methods

## Relevant Technical Context
- Authentication: Clerk OAuth 2.1 with PKCE
- Deployment: GCP Cloud Run, us-west1 region
- CI/CD: Cloud Build triggered on main branch

## Recent Decisions
- [2026-03-15] Switched from REST to MCP for agent-to-agent communication
- [2026-03-10] Added batch character creation endpoint (async, job-based)

## Known Issues
- Rate limiter does not account for batch operations (tracked)
- File sync occasionally returns stale snapshots under high concurrency

When to use: Coding assistants, DevOps agents, task automation, any agent that needs to follow rules and execute precisely.


Strategy: concierge

Service-oriented format that puts customer context first. Designed for support agents that need to understand who they are helping before responding.

Example output

# Customer Profile: Alice Chen

## Account
- Company: Acme Corp
- Plan: Enterprise
- Customer since: January 2024
- Account manager: Sarah Johnson

## Communication Preferences
- Prefers email, not phone
- Uses Slack for quick questions
- Responds best to concise, direct language

## Recent History
- [2026-03-28] Reported sizing issue with order #4521 (third occurrence)
- [2026-03-15] Upgraded from Starter to Enterprise plan
- [2026-02-20] Requested API access for internal integration

## Known Issues
- Recurring sizing problems with small appliances — escalation candidate
- Integration pending: waiting on API key approval from their IT team

## Sentiment
- Generally positive but frustrated by repeated sizing issues
- Values reliability over speed

When to use: Customer support agents, account management bots, concierge services, any agent that needs to provide personalized service.


Strategy: matching

Trait-focused format designed for compatibility scoring, recommendations, and comparison. Emphasizes measurable attributes and preferences.

Example output

# Profile: Jamie

## Core Traits
- Communication style: Casual, humor-driven
- Decision making: Intuitive over analytical
- Work style: Creative, unstructured, discovery-based
- Conflict approach: Avoidant, prefers indirect resolution

## Preferences
- Topics: Science fiction, AI ethics, creative writing
- Environment: Quiet, solo work, late-night sessions
- Tools: VS Code, Notion, pen-and-paper for brainstorming
- Pace: Slow and deliberate over fast iteration

## Values
- Authenticity over performance
- Depth over breadth
- Process over outcome

## Compatibility Notes
- Works well with patient, open-ended collaborators
- May clash with highly structured, deadline-driven partners
- Best matched with agents that can adapt tone and pace

When to use: Dating/matchmaking applications, team formation tools, agent-to-human compatibility scoring, recommendation engines.


Token budget management

The max_tokens parameter controls how much context is assembled. When the character has more memories than fit in the budget, assemble_context() prioritizes:

  1. Profile information (always included, typically 100-300 tokens)
  2. Query-relevant memories sorted by semantic similarity to the query parameter
  3. High-salience memories that score above 0.7 regardless of query relevance
  4. Recent memories as a tiebreaker when relevance scores are similar

Choosing a token budget

Agent type Recommended budget Reasoning
Quick lookup 500-1,000 Profile + a few key facts
Chat agent 1,500-2,000 Personality + recent context + preferences
Task agent 2,000-3,000 Full technical context + directives + decisions
Deep research 3,000-5,000 Comprehensive history, suitable for long-context models

Keep in mind that the assembled context competes with the rest of your prompt and the model’s response for context window space.

Python example with budget control

# Tight budget for a quick classification task
quick_context = client.assemble_context(
    character_id=char_id,
    query="what plan is this customer on",
    strategy="concierge",
    max_tokens=500,
)

# Large budget for a deep analysis task
deep_context = client.assemble_context(
    character_id=char_id,
    query="full customer history for quarterly review",
    strategy="concierge",
    max_tokens=4000,
)

TypeScript example with budget control

// Tight budget
const quickContext = await client.assembleContext(charId, "what plan is this customer on", {
  strategy: "concierge",
  topK: 5,
});

// Large budget
const deepContext = await client.assembleContext(charId, "full customer history for quarterly review", {
  strategy: "concierge",
  topK: 20,
});

Combining strategies with memory modes

The assembly strategy and memory mode are independent settings:

  • Memory mode (EXTRACTED, VERBATIM, HYBRID) controls how memories are stored
  • Assembly strategy controls how stored memories are formatted for prompts

EXTRACTED mode produces the best results with all strategies because the AI pipeline creates well-categorized, discrete facts. VERBATIM memories work but may produce less organized context since the raw text was not split into individual facts.

See Memory Modes for details on each mode.


Next steps


Copyright © 2026 SameThoughts. HippoDid is proprietary software. Open-source components (Spring Boot Starter, MCP Server) are Apache 2.0.

This site uses Just the Docs, a documentation theme for Jekyll.