Skip to content

0xtotem/peek-dspy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

peek-dspy

A DSPy port of PEEK: a self-updating context map that lives in your agent's prompt and accumulates structural knowledge about a recurring external context (a repo, a corpus, a document set) across calls.

Wrap any dspy.Module. The map grows automatically; a token budget keeps it bounded.

import dspy
from peek_dspy import PEEK

class QA(dspy.Signature):
    """Answer a question about the codebase."""
    question: str = dspy.InputField()
    answer:   str = dspy.OutputField()

dspy.configure(lm=dspy.LM("anthropic/claude-sonnet-4-6"))

agent  = dspy.ReAct(QA, tools=[read_file, grep, list_files])
policy = PEEK(
    agent,
    token_budget=10_000,       # max tokens kept in the context map
    freeze_after=3,            # stop updating after N calls (None = always update)
    question_field="question", # field forwarded to the distiller as the task description
)

for q in questions:
    pred = policy(question=q)  # map accumulates here
    print(pred.answer)

print(policy.current_map_text)

After each call, a Distiller separates orientation work from question-specific work, a Cartographer emits ADD / DELETE / REPLACE edits, and an Evictor trims the map to token_budget by dropping low-value sections first.

Install

poetry install
export ANTHROPIC_API_KEY=sk-...
poetry run python examples/codebase_qa.py

References

Paper: arxiv.org/abs/2605.19932

Upstream: github.com/zhuohangu/peek

About

A DSPy port of PEEK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages