cd /Users/saish/Downloads/Context_engineering/context_pruning
crewai installOr manually:
uv pip install -e .Make sure your .env file contains:
GEMINI_API_KEY=your-actual-gemini-api-key-here
MODEL=gemini/gemini-flash-latestcrewai run- Retrieval Agent searches Lilian Weng's blog posts for information about reward hacking
- Pruning Agent filters the content to remove irrelevant information
- Response Synthesizer creates a comprehensive answer
- Result saved to
context_pruning_result.md
Default query: "What are the types of reward hacking discussed in the blogs?"
Expected workflow:
[Retrieval Agent] Searching blog posts...
β Retrieved ~15,000 tokens of content
[Pruning Agent] Filtering content...
β Pruned to ~6,000 relevant tokens (60% reduction)
[Response Synthesizer] Creating answer...
β Generated comprehensive markdown response
Edit src/context_pruning/main.py:
inputs = {
'topic': 'hallucination in LLMs',
'query': 'What causes hallucination in large language models?'
}Then run again:
crewai runCheck the generated file:
cat context_pruning_result.mdImport errors?
crewai installAPI key issues?
- Verify GEMINI_API_KEY in
.env - Test with:
echo $GEMINI_API_KEY
Want more verbose output?
- Agents already set to
verbose=Trueincrew.py - Check terminal for detailed execution logs
- Compare with LangGraph implementation:
../how_to_fix_your_context/notebooks/04-context-pruning.ipynb - Read full README:
README.md - Explore other context engineering techniques
- First run is slower - Vector store initialization takes time
- Check token counts - Watch the logs to see pruning effectiveness
- Experiment with queries - Try different topics from the blog posts:
- Thinking mechanisms in AI
- Hallucination causes and solutions
- Diffusion models for video
- Reward hacking categories
Happy Context Pruning! π