from anchor import ContextPipeline, QueryBundle, MemoryManager# Create pipeline with memorymemory = MemoryManager(conversation_tokens=4096)pipeline = ( ContextPipeline(max_tokens=8192) .with_memory(memory) .add_system_prompt("You are a helpful coding assistant."))# Add conversation historymemory.add_user_message("Help me write a Python function")memory.add_assistant_message("Sure! What should the function do?")# Build context for the next queryresult = pipeline.build(QueryBundle(query_str="It should sort a list"))print(result.formatted_output)
MemoryManager stores conversation turns in a sliding window capped at
4 096 tokens.
ContextPipeline assembles a context window of up to 8 192 tokens,
placing the system prompt first (highest priority), then conversation
memory, then any retrieval results.
build() packs everything that fits into a ContextResult -- ready to
send to any LLM.
[!TIP] String shorthand
build() also accepts a plain string. These two calls are equivalent:
result = pipeline.build("It should sort a list")result = pipeline.build(QueryBundle(query_str="It should sort a list"))
This pipeline has no retrieval -- it only uses memory and a system prompt. To
add semantic search, hybrid retrieval, token budgets, formatters, and more,
continue to Your First Pipeline.