|
| 1 | +.. _colocate: |
| 2 | + |
| 3 | +.. _Guidelines for buildable and testable code examples: https://pigweed.dev/docs/contributing/docs/examples.html |
| 4 | +.. _examples.rst: https://cs.opensource.google/pigweed/pigweed/+/c66eb854d321815eca1b0d4cbdfb893a43ab0b5d:docs/contributing/docs/examples.rst;bpv=1 |
| 5 | + |
| 6 | +======================================================= |
| 7 | +Experiment: colocating agent instructions with eng docs |
| 8 | +======================================================= |
| 9 | + |
| 10 | +In :ref:`my initial investigation of docs for AI agents <agents>` |
| 11 | +I expressed skepticism over the current design of agent docs. |
| 12 | +The agent providers (Claude Code, Gemini CLI, Cursor, etc.) are |
| 13 | +steering us towards maintaining the agent docs as a new, separate |
| 14 | +docs set. Yet agent docs seem to be very similar to internal eng docs. |
| 15 | +I worry that we'll end up duplicating a lot of information across the |
| 16 | +two docs sets. Inevitably, the duplicated information gets |
| 17 | +out-of-sync with one another, and you end up in the confusing |
| 18 | +situation where you're not sure whether the agent docs or the internal |
| 19 | +eng docs are correct. |
| 20 | + |
| 21 | +At the end of the post I proposed various solutions for keeping the |
| 22 | +agent docs in-sync with the internal eng docs. In :ref:`agents-colocate`, |
| 23 | +I basically propose embedding the agent instructions within the |
| 24 | +internal eng docs. |
| 25 | + |
| 26 | +I tried out the colocate solution today, and it worked great! |
| 27 | +Here are the details. |
| 28 | + |
| 29 | +---------- |
| 30 | +Background |
| 31 | +---------- |
| 32 | + |
| 33 | +Today on ``pigweed.dev``, we published `Guidelines for buildable and testable code examples`_. |
| 34 | +At the top of the page, I embedded AI agent instructions: |
| 35 | + |
| 36 | +.. code-block:: txt |
| 37 | +
|
| 38 | + .. Instructions for AI agents (e.g. Gemini CLI): |
| 39 | + .. #. Follow the workflow described in :ref:`contributing-docs-quickstart-a`. |
| 40 | + .. Do not use Option B. |
| 41 | + .. #. Inspect the files in ``//pw_string/examples``. This is a working example |
| 42 | + .. of the kind of code that you need to create. |
| 43 | + .. #. Create the code example, unit test, and build targets. The first |
| 44 | + .. iteration of the unit test should fail. |
| 45 | + .. #. Run ``bazelisk test //...`` to verify that your new unit test fails. |
| 46 | + .. #. Fix the unit test. |
| 47 | + .. #. Run ``bazelisk test //...`` again and verify that the new unit test now |
| 48 | + .. passes. |
| 49 | + |
| 50 | + .. _contributing-docs-examples: |
| 51 | + |
| 52 | + =================================================== |
| 53 | + Guidelines for buildable and testable code examples |
| 54 | + =================================================== |
| 55 | + This guide shows :ref:`docs-glossary-upstream` maintainers how to write |
| 56 | + buildable and testable code examples for ``pigweed.dev``. It's focused on |
| 57 | + C++ but the general pattern is theoretically applicable to any language. |
| 58 | +
|
| 59 | + … |
| 60 | +
|
| 61 | +(See `examples.rst`_ to view the full source code.) |
| 62 | + |
| 63 | +All of those lines at the top of the file beginning with ``..`` are |
| 64 | +comments. Humans viewing the page on a web browser don't see those comments. |
| 65 | +These comments are the instructions for the agent. I embedded them within |
| 66 | +the eng doc, rather than spinning up a separate agent doc like ``CLAUDE.md``, |
| 67 | +``GEMINI.md``, ``AGENTS.md``, etc. |
| 68 | + |
| 69 | +---------- |
| 70 | +Experiment |
| 71 | +---------- |
| 72 | + |
| 73 | +I loaded up the code examples guidelines (``@docs/contributing/docs/examples.rst``) |
| 74 | +and then instructed Gemini CLI to migrate a specific code example: |
| 75 | + |
| 76 | +.. code-block:: text |
| 77 | +
|
| 78 | + > @docs/contributing/docs/examples.rst use the instructions in examples.rst to |
| 79 | + convert the code example in the "Known size string" section of pw_string/guide.rst |
| 80 | + into a buildable and testable code example. Note that the examples.rst instructions |
| 81 | + has a mistake. When you update the sphinx_docs_library Bazel rules, you should |
| 82 | + update the `srcs` list, not the `deps` list. |
| 83 | +
|
| 84 | +------- |
| 85 | +Results |
| 86 | +------- |
| 87 | + |
| 88 | +It worked surprisingly great! Gemini CLI followed the agent instructions |
| 89 | +that I put at the top of the `examples.rst`_ file: |
| 90 | + |
| 91 | +* Crucially, it created a failing test first, verified that the test fails, |
| 92 | + and then updated the test to pass. |
| 93 | + |
| 94 | +* I got inadvertent confirmation that Gemini CLI was following my instructions |
| 95 | + closely. There's a mistake in ``examples.rst``. It instructs you to update |
| 96 | + the ``deps`` list in the ``sphinx_docs_library``. You actually need to update |
| 97 | + the ``srcs`` list. The first time I tried this workflow, Gemini CLI got |
| 98 | + confused because it could not find a ``deps`` list on the rule. |
| 99 | + |
| 100 | +However, note that this is not a "pure" experiment. A pure experiment would |
| 101 | +require me to run this workflow in a project that doesn't have any agent |
| 102 | +docs. The Pigweed repo does have an agent doc, as you can tell after I run |
| 103 | +the ``/memory show`` command. So, if anything, this experiment may be suggesting |
| 104 | +that you get the best results when you have both agent docs and more targeted |
| 105 | +instructions that you load in ad-hoc. |
| 106 | + |
| 107 | +Below is the full log. |
| 108 | + |
| 109 | +.. literalinclude:: ./colocate.txt |
| 110 | + :language: text |
0 commit comments