Skip to content
Back to search

context-engineering

Context Engineering: Build Consistent, Accurate, Predictable AI Systems

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/bonigarcia/context-engineering with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/bonigarcia/context-engineering'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/bonigarcia--context-engineering/badge.svg)](/listings/bonigarcia--context-engineering)

HTML

<a href="/listings/bonigarcia--context-engineering"><img src="/api/listings/bonigarcia--context-engineering/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 210 lines · 1 finding marked

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # Context Engineering ![](https://bonigarcia.dev/img/context-engineering.png)
  2. **Context engineering** can be defined as the practice of designing systems that provide a Large Language Model (LLM) and AI agents with all the necessary information to complete a task effectively. It goes beyond prompt engineering since it focuses on building a comprehensive and structured context from various sources like instructions, external knowledge, memory, tools, and state. The central idea is that the success of a complex LLM-based system depends more on the quality and completeness of the context provided than on the specific wording of the prompt itself.
  3. Tobi Lütke, the CEO of Shopify, coined the term _context engineering_ in a [tweet](https://x.com/tobi/status/1935533422589399127) on June 19, 2025. He defined context engineering as _the art of providing all the context for the task to be plausibly solvable by the LLM_. This novel concept captures the essence of the current evolution of LLM-based systems, inspiring others (like me) to understand and define this emerging discipline. Since then, I've been working on a book entitled **Context Engineering: Build Consistent, Accurate, Predictable AI Systems**, published by Manning. Currently, the early access version of the book is available, and you can get it [here](https://hubs.la/Q04ksQ8J0).
  4. [![Context Engineering](./docs/img/context-engineering-MEAP-cover.png)](https://hubs.la/Q04ksQ8J0)
  5. This GitHub repository is intended to be a companion resource for this book and a reference for practitioners looking to understand and adopt the context engineering principles.
  6. ## Table of contents
  7. This book aims to provide a strong, general-purpose theoretical foundation for context engineering, supported by hands-on examples. Its table of contents is the following:
  8. 1. Introduction to context engineering
  9. 2. Instructions for AI agents
  10. 3. External knowledge and retrieval
  11. 4. Tools in AI agents
  12. 5. Memory and state in agentic systems
  13. 6. User prompts for LLMs
  14. 7. Context management and orchestration
  15. 8. Evaluation and observability
  16. 9. Governance and operations
  17. 10. AI frameworks for context engineering
  18. 11. Context engineering for software development
  19. 12. The state of the art in context engineering
  20. Appendix A. The AI ecosystem
  21. Appendix B. References and further reading
  22. Each chapter of this book begins by explaining the underlying principles and patterns of each thematic block. The final part of each chapter then presents specific examples, all of which are available in this GitHub repository. New examples will continue to be added, and existing ones maintained, even after the book is published. The goal is to provide an open-source, up-to-date reference for everyone interested in context engineering.
  23. ## Examples
  24. This repository organizes examples by chapter to help you explore context engineering concepts in practice.
  25. #### Chapter 1. Introduction to context engineering
  26. This chapter provides the foundations for interacting with different model providers:
  27. - Basic interaction (OpenAI): [Python](./ch01/python/openai-gpt-basic) · [Jupyter](./ch01/jupyter/openai-gpt-basic.ipynb) · [JavaScript](./ch01/javascript/openai-gpt-basic) · [Java](./ch01/java/src/main/java/io/github/bonigarcia/ce/OpenAiGptBasic.java)
  28. - Streaming (OpenAI): [Python](./ch01/python/openai-gpt-streaming) · [Jupyter](./ch01/jupyter/openai-gpt-streaming.ipynb) · [JavaScript](./ch01/javascript/openai-gpt-streaming) · [Java](./ch01/java/src/main/java/io/github/bonigarcia/ce/OpenAiGptStreaming.java)
  29. - Basic interaction (Anthropic): [Python](./ch01/python/anthropic-claude-basic) · [Jupyter](./ch01/jupyter/anthropic-claude-basic.ipynb) · [JavaScript](./ch01/javascript/anthropic-claude-basic) · [Java](./ch01/java/src/main/java/io/github/bonigarcia/ce/AnthropicClaudeBasic.java)
  30. - Streaming (Anthropic): [Python](./ch01/python/anthropic-claude-streaming) · [Jupyter](./ch01/jupyter/anthropic-claude-streaming.ipynb) · [JavaScript](./ch01/javascript/anthropic-claude-streaming) · [Java](./ch01/java/src/main/java/io/github/bonigarcia/ce/AnthropicClaudeStreaming.java)
  31. - Basic interaction (Google): [Python](./ch01/python/google-gemini-basic) · [Jupyter](./ch01/jupyter/google-gemini-basic.ipynb) · [JavaScript](./ch01/javascript/google-gemini-basic) · [Java](./ch01/java/src/main/java/io/github/bonigarcia/ce/GoogleGeminiBasic.java)
  32. - Streaming (Google): [Python](./ch01/python/google-gemini-streaming) · [Jupyter](./ch01/jupyter/google-gemini-streaming.ipynb) · [JavaScript](./ch01/javascript/google-gemini-streaming) · [Java](./ch01/java/src/main/java/io/github/bonigarcia/ce/GoogleGeminiStreaming.java)
  33. - Basic interaction (Ollama): [Python](./ch01/python/ollama-local-basic) · [Jupyter](./ch01/jupyter/ollama-local-basic.ipynb) · [JavaScript](./ch01/javascript/ollama-local-basic) · [Java](./ch01/java/src/main/java/io/github/bonigarcia/ce/OllamaLocalBasic.java)
  34. - Streaming (Ollama): [Python](./ch01/python/ollama-local-streaming) · [Jupyter](./ch01/jupyter/ollama-local-streaming.ipynb) · [JavaScript](./ch01/javascript/ollama-local-streaming) · [Java](./ch01/java/src/main/java/io/github/bonigarcia/ce/OllamaLocalStreaming.java)
  35. #### Chapter 2. Instructions for AI agents
  36. This chapter covers the definition and usage of instructions (system prompts, agent skills, instructions artifacts) as a foundation layer to shape the model behavior:
  37. - System prompts (OpenAI): [Python](./ch02/python/openai-gpt-system-prompt) · [Jupyter](./ch02/jupyter/openai_gpt_system_prompt.ipynb) · [JavaScript](./ch02/javascript/openai-gpt-system-prompt) · [Java](./ch02/java/src/main/java/io/github/bonigarcia/ce/OpenAiGptSystemPrompt.java)
  38. - System prompts (Anthropic): [Python](./ch02/python/anthropic-claude-system-prompt) · [Jupyter](./ch02/jupyter/anthropic_claude_system_prompt.ipynb) · [JavaScript](./ch02/javascript/anthropic-claude-system-prompt) · [Java](./ch02/java/src/main/java/io/github/bonigarcia/ce/AnthropicClaudeSystemPrompt.java)
  39. - System prompts (Google): [Python](./ch02/python/google-gemini-system-prompt) · [Jupyter](./ch02/jupyter/google_gemini_system_prompt.ipynb) · [JavaScript](./ch02/javascript/google-gemini-system-prompt) · [Java](./ch02/java/src/main/java/io/github/bonigarcia/ce/GoogleGeminiSystemPrompt.java)
  40. - System prompts (Ollama): [Python](./ch02/python/ollama-local-system-prompt) · [Jupyter](./ch02/jupyter/ollama_local_system_prompt.ipynb) · [JavaScript](./ch02/javascript/ollama-local-system-prompt) · [Java](./ch02/java/src/main/java/io/github/bonigarcia/ce/OllamaLocalSystemPrompt.java)
  41. - Agent skills: [project-notetaker](./ch02/agent-skills/project-notetaker)
  42. - Instruction artifacts: [task-tracker](./ch02/python/instruction-artifacts)
  43. #### Chapter 3. External knowledge and retrieval
  44. This chapter explores different patterns for providing external knowledge to a model:
  45. - Retrieval-Augmented Generation (RAG): [OpenAI (Python)](./ch03/python/rag-openai) · [OpenAI (Jupyter)](./ch03/jupyter/rag_openai.ipynb) · [Hugging Face (Python)](./ch03/python/rag-hugging-face) · [Hugging Face (Jupyter)](./ch03/jupyter/rag_hugging_face.ipynb)
  46. - Advanced RAG: [LangChain](./ch03/python/agentic-rag) · [Qdrant](./ch03/python/local-rag) · [PageIndex (Python)](./ch03/python/vectorless-rag-pageindex) · [PageIndex (Jupyter)](./ch03/jupyter/vectorless_rag_pageindex.ipynb) · [RAGFlow](./ch03/python/ragflow-basic)
  47. - Context stuffing: [System prompt (Python)](./ch03/python/context-stuffing-system-prompt) · [System prompt (Jupyter)](./ch03/jupyter/context_stuffing_system_prompt.ipynb) · [User prompt (Python)](./ch03/python/context-stuffing-user-prompt) · [User prompt (Jupyter)](./ch03/jupyter/context_stuffing_user_prompt.ipynb)
  48. - Cache-Augmented Generation (CAG): [Python](./ch03/python/cag) · [Jupyter](./ch03/jupyter/cag.ipynb)
  49. #### Chapter 4. Tools in AI agents
  50. This chapter focuses on extending the capabilities of AI agents through tools:
  51. - Function calling: [Python](./ch04/python/function_calling) · [JavaScript](./ch04/javascript/function_calling) · [Java](./ch04/java/function_calling)
  52. - Command-Line Interface (CLI): [workspace-analyzer](./ch04/agent-skills/workspace-analyzer)
  53. - Model Context Protocol (MCP) server: [Python](./ch04/python/mcp_server) · [JavaScript](./ch04/javascript/mcp_server) · [Java](./ch04/java/mcp_server)
  54. #### Chapter 5. Memory and state in agentic systems
  55. This chapter explores how to maintain information across interactions using memory and state:
  56. - Session memory: [Python](./ch05/python/session_memory_chat)
  57. - Long-term memory (Mem0): [Python](./ch05/python/mem0_chat) · [JavaScript](./ch05/javascript/mem0_chat) · [Java](./ch05/java/src/main/java/io/github/bonigarcia/ce/Mem0Chat.java)
    • Dismissed after review: Contains a long base64-looking blob — not necessarily malicious, but worth inspecting what it decodes to
    • Line 72 on GitHub
  58. - Long-term memory (Cognee): [Python](./ch05/python/cognee_memory)
  59. - Memory coach: [Python](./ch05/python/memory_coach)
  60. - Session state: [Python](./ch05/python/session_state_chat) · [JavaScript](./ch05/javascript/session_state_chat) · [Java](./ch05/java/src/main/java/io/github/bonigarcia/ce/SessionStateChat.java)
  61. - Workflow state: [Python](./ch05/python/workflow_state_handoff) · [JavaScript](./ch05/javascript/workflow_state_handoff) · [Java](./ch05/java/src/main/java/io/github/bonigarcia/ce/WorkflowStateHandoff.java)
  62. #### Chapter 6. User prompts for LLMs
  63. This chapter focuses on the design and optimization of user prompts, including techniques like few-shot prompting, prompt chaining, Chain-of-Thought, or ReAct:
  64. - Few-shot prompting: [Python](./ch06/python/few-shot-ticket-normalizer) · [Jupyter](./ch06/jupyter/few-shot-ticket-normalizer.ipynb) · [JavaScript](./ch06/javascript/few-shot-ticket-normalizer) · [Java](./ch06/java/src/main/java/io/github/bonigarcia/ce/FewShotTicketNormalizer.java)
  65. - Prompt chaining: [Python](./ch06/python/prompt-chaining-support-reply) · [Jupyter](./ch06/jupyter/prompt-chaining-support-reply.ipynb) · [JavaScript](./ch06/javascript/prompt-chaining-support-reply) · [Java](./ch06/java/src/main/java/io/github/bonigarcia/ce/PromptChainingSupportReply.java)
  66. - Chain-of-Thought vs ReAct (DSPy): [Python](./ch06/python/dspy-cot-vs-react) · [Jupyter](./ch06/jupyter/dspy_cot_vs_react.ipynb)
  67. #### Chapter 7. Context management and orchestration
  68. This chapter focuses on managing and orchestrating context in complex agentic systems, including context compression, hierarchical context, or multi-agent patterns:
  69. - Context compression: [LLMLingua](./ch07/context-compression)
  70. - Filesystem context: [OpenViking](./ch07/openviking-filesystem)
  71. - Collaborative agents: [CrewAI](./ch07/crewai-crew)
  72. - Multi-agent router: [LangGraph](./ch07/multi-agent-router)
  73. - Orchestration: [DeepAgents](./ch07/deepagents-orchestration)
  74. - Agent-to-Agent (A2A): [Python](./ch07/a2a-example)
  75. #### Chapter 8. Evaluation and observability
  76. This chapter covers evaluation and observability for context-aware systems:
  77. - Metrics: [DeepEval](./ch08/metrics-deepeval)
  78. - Evals: [Promptfoo](./ch08/evals-promptfoo)
  79. - LLM-as-judge: [Ragas](./ch08/llm-as-judge-ragas)
  80. - Observability: [Langfuse](./ch08/observability-langfuse)
  81. - Observability: [LangSmith](./ch08/observability-langsmith)
  82. #### Chapter 9. Governance and operations
  83. This chapter covers governance, human oversight, and operational patterns for context-aware systems:
  84. - Personally Identifiable Information (PII) redaction: [Microsoft Presidio](./ch09/pii_presidio)
  85. - Output validation: [Pydantic](./ch09/output_validation)
  86. - Bias detection: [Fairlearn](./ch09/bias_detection)
  87. - AI gateway: [LiteLLM](./ch09/litellm_gateway)
  88. - Human-in-the-loop: [Python](./ch09/human-in-the-loop)
  89. - Model fine-tuning: [Python](./ch09/fine_tuning)
  90. - Context as code: [Python](./ch09/context_as_code)
  91. #### Chapter 10. AI frameworks for context engineering
  92. This chapter covers specific AI frameworks that facilitate context engineering, including application frameworks, agent orchestration frameworks, and AI application platforms:
  93. - AI application frameworks: [LangChain](./ch10/langchain) · [LlamaIndex](./ch10/llamaindex) · [Haystack](./ch10/haystack) · [Spring AI](./ch10/spring_ai) · [LangChain4j](./ch10/langchain4j) · [Pydantic AI](./ch10/pydantic_ai) · [DSPy](./ch10/dspy) · [AI SDK](./ch10/ai_sdk)
  94. - Agent orchestration frameworks: [LangGraph](./ch10/langgraph) · [CrewAI](./ch10/crewai) · [Agent Development Kit](./ch10/adk) · [Microsoft Agent Framework](./ch10/agent_framework) · [Agno](./ch10/agno) · [Embabel](./ch10/embabel) · [Parlant](./ch10/parlant) · [DeepAgents](./ch10/deepagents) · [Claude Agent SDK](./ch10/claude_agent_sdk)
  95. - AI application platforms: [Zapier](./ch10/zapier) · [n8n](./ch10/n8n) · [OpenClaw](./ch10/openclaw) · [Temporal](./ch10/temporal) · [Amazon Bedrock AgentCore](./ch10/bedrock_agentcore) · [Gemini Enterprise Agent Platform](./ch10/gemini_agent_platform)
  96. #### Chapter 11. Context engineering for software development
  97. This chapter shows how context engineering supports the software development lifecycle (SDLC) through reusable skills, instruction artifacts, external documentation retrieval, orchestration layers, and specialized agents:
  98. - Agent skills: [Claude Code](./ch11/claude-code-agent-skills)
  99. - Instructions artifact: [Cursor rules](./ch11/karpathy-instructions-cursor)
  100. - Documentation retrieval: [Codex with Context7](./ch11/codex-context7)
  101. - SDLC prompt library: [SDLC prompt library](./ch11/sdlc-prompt-library)
  102. - Specification-driven development: [Spec Kit](./ch11/spec-kit-sdd)
  103. - Orchestration: [OpenCode Superpowers](./ch11/opencode-superpowers) · [Antigravity Open GSD](./ch11/antigravity-open-gsd) · [BMAD specialized agents](./ch11/bmad-specialized-agents)
  104. #### Chapter 12. The state of the art in context engineering
  105. This chapter covers mathematical foundations, open research challenges, technical innovation frontiers, domain-specific applications, and future directions:
  106. - Technology radar: [Context engineering radar](./ch12/context_engineering_radar)
  107. - Base knowledge: [Graphify base knowledge](./ch12/base_knowledge)
  108. ## Online resources
  109. This repository includes interactive [web pages](https://bonigarcia.dev/context-engineering/) that complement the book and help you apply context engineering concepts in practice.
  110. ### 1. AI Ecosystem
  111. 🔗 https://bonigarcia.dev/context-engineering/ai-ecosystem.html
  112. Curated collection of the AI ecosystem:
  113. - Browse model families, agents, frameworks, and tooling in one place
  114. - Search across the appendix snapshot by name, feature, license, or pricing
  115. This page is a companion index for the Appendix A and is designed to stay easy to maintain as the ecosystem changes.
  116. ---
  117. ### 2. Context-Aware Prompt Builder
  118. 🔗 https://bonigarcia.dev/context-engineering/context-aware-prompt-builder.html
  119. Design, compare, and reuse structured prompts across multiple frameworks and AI models:
  120. - Build prompts using established frameworks (10-step, COSTAR, CRISPE, RTF, etc.)
  121. - Switch frameworks dynamically while preserving intent
  122. - Import/export prompts as JSON
  123. - Measure approximate context usage for different models
  124. - Load curated prompt samples for common SDLC roles
  125. This tool is especially useful for creating and iterating on prompts in a structured, repeatable way.
  126. ---
  127. ### 3. SDLC Prompt Library
  128. 🔗 https://bonigarcia.dev/context-engineering/sdlc_prompt_library.html
  129. Browse a curated library of prompts organized around the software development lifecycle (SDLC), including roles for architect, developer, debugger, reviewer, refactorer, tester, and documenter:
  130. - Explore prompts visually using a card-based interface
  131. - Filter by framework (10-step, COSTAR, CRISPE, RTF)
  132. - Inspect full structured prompts for each role
  133. - Copy prompts directly for reuse or adaptation
  134. This tool is designed as a reference library, helping you understand how structured prompts vary across roles and frameworks.
  135. ---
  136. ### 4. Context Engineering Radar
  137. 🔗 https://bonigarcia.dev/context-engineering/context-engineering-radar.html
  138. An interactive dashboard to explore and track concepts, sources, frameworks, and publications in the field of context engineering:
  139. - Circular radar visualization using SVG geometry and polar coordinates mapping
  140. - Classify resources across Primary, Secondary, and Tertiary ring levels
  141. - Group items in distinct quadrants: Literature, Frameworks, Models, and Communities
  142. - Dynamic searching, category filters, and detailed description modal overlays
  143. ---
  144. ### 5. Further Reading
  145. 🔗 https://bonigarcia.dev/context-engineering/references.html
  146. Searchable catalog of articles, books, repositories, tutorials, and other references related to context engineering, prompting, agents, and AI engineering: context engineering, AI agents, machine learning, prompt engineering, RAG, generative AI, MCP, AI-assisted development, LLMs, memory, retrieval, multi-agent systems.
  147. ## Contributing
  148. If you think something should be improved or want to contribute to this repo, please open a [pull request](https://github.com/bonigarcia/context-engineering/pulls). Any comments or feedback are welcome.
  149. ## About
  150. context-engineering (Copyright &copy; 2025-2026) is an open-source project created and maintained by [Boni Garcia](https://bonigarcia.dev/), licensed under the terms of [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0).

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.