%23%20%2F%2F%2F%20script%0A%23%20requires-python%20%3D%20%22%3E%3D3.11%22%0A%23%20dependencies%20%3D%20%5B%0A%23%20%20%20%20%20%22marimo%3E%3D0.24.0%22%2C%0A%23%20%5D%0A%23%20%2F%2F%2F%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.24.0%22%0Aapp%20%3D%20marimo.App(%0A%20%20%20%20width%3D%22medium%22%2C%0A%20%20%20%20layout_file%3D%22data%3Aapplication%2Fjson%3Bbase64%2CewogICJ0eXBlIjogInNsaWRlcyIsCiAgImRhdGEiOiB7CiAgICAiY2VsbHMiOiBbCiAgICAgIHt9LAogICAgICB7fSwKICAgICAge30sCiAgICAgIHt9LAogICAgICB7fSwKICAgICAge30sCiAgICAgIHt9LAogICAgICB7fSwKICAgICAge30sCiAgICAgIHt9LAogICAgICB7fSwKICAgICAge30sCiAgICAgIHt9LAogICAgICB7fSwKICAgICAge30sCiAgICAgIHt9LAogICAgICB7fSwKICAgICAge30sCiAgICAgIHt9LAogICAgICB7fSwKICAgICAge30sCiAgICAgIHt9LAogICAgICB7fSwKICAgICAge30sCiAgICAgIHt9LAogICAgICB7fSwKICAgICAge30sCiAgICAgIHt9LAogICAgICB7fSwKICAgICAge30sCiAgICAgIHt9LAogICAgICB7fSwKICAgICAge30sCiAgICAgIHt9LAogICAgICB7fSwKICAgICAge30sCiAgICAgIHt9LAogICAgICB7fSwKICAgICAge30sCiAgICAgIHt9CiAgICBdLAogICAgImRlY2siOiB7fQogIH0KfQ%3D%3D%22%2C%0A)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20json%0A%20%20%20%20import%20subprocess%0A%20%20%20%20import%20sys%0A%20%20%20%20from%20pathlib%20import%20Path%0A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20ollama%0A%0A%20%20%20%20sys.path.insert(0%2C%20str(mo.notebook_dir()))%0A%20%20%20%20import%20workshop%0A%20%20%20%20from%20workshop%20import%20harness%2C%20trace%0A%20%20%20%20from%20workshop.mcp_bridge%20import%20McpSource%2C%20to_ollama_tool%0A%0A%20%20%20%20WORK%20%3D%20mo.notebook_dir()%20%2F%20%22work%22%20%20%20%20%20%20%20%20%20%20%23%20clones%20live%20here%20(git-ignored)%0A%20%20%20%20ARGS%20%3D%20mo.cli_args()%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%60uv%20run%20agent.py%20--%20--issue%20URL%20--model%20NAME%60%0A%0A%20%20%20%20def%20task(md%3A%20str)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Slides%20that%20ask%20YOU%20to%20do%20something%20look%20like%20this.%22%22%22%0A%20%20%20%20%20%20%20%20return%20mo.callout(mo.md(%22%23%23%23%20%F0%9F%91%89%20Your%20turn%5Cn%22%20%2B%20md)%2C%20kind%3D%22warn%22)%0A%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20ARGS%2C%0A%20%20%20%20%20%20%20%20McpSource%2C%0A%20%20%20%20%20%20%20%20WORK%2C%0A%20%20%20%20%20%20%20%20harness%2C%0A%20%20%20%20%20%20%20%20mo%2C%0A%20%20%20%20%20%20%20%20ollama%2C%0A%20%20%20%20%20%20%20%20subprocess%2C%0A%20%20%20%20%20%20%20%20sys%2C%0A%20%20%20%20%20%20%20%20task%2C%0A%20%20%20%20%20%20%20%20to_ollama_tool%2C%0A%20%20%20%20%20%20%20%20trace%2C%0A%20%20%20%20%20%20%20%20workshop%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Local%20Agent%20Workshop%20%40%20IFI%0A%0A%20%20%20%200.%20Overview%2C%20prerequisites%0A%20%20%20%201.%20LLM%20inference%20(via%20Ollama)%0A%20%20%20%202.%20Tool%20calling%0A%20%20%20%203.%20Model%20Context%20Protocol%0A%20%20%20%204.%20Solving%20issues%20from%20GitHub%0A%20%20%20%205.%20Ready%20harnesses%0A%0A%20%20%20%20By%20the%20end%20you%20run%20%60uv%20run%20agent.py%20--%20--issue%20%3Curl%3E%60%20and%20it%20opens%20a%20PR.%0A%20%20%20%20Orange%20boxes%20are%20exercises.%20Solutions%20are%20in%20%60agent.py%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%200.1%20%60whoami%60%0A%0A%20%20%20%20-%20studied%20at%20TU%20Delft%0A%20%20%20%20-%20experimented%20with%20transformers%0A%20%20%20%20-%20now%20training%20Mellum%20models%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%200.2%20What%20is%20an%20LLM%3F%0A%0A%20%20%20%20%20%20%20%20A%20transformer%20predicting%20the%20next%20token%2C%20over%20and%20over.%0A%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%20%20%20%20mo.mermaid(%22%22%22%0A%20%20%20%20%20%20%20%20flowchart%20LR%0A%20%20%20%20%20%20%20%20%20%20P%5B%22prompt%20tokens%3Cbr%2F%3E%5BThe%2C%20cat%2C%20sat%2C%20on%2C%20the%5D%22%5D%20--%3E%20T%5B%22transformer%3Cbr%2F%3E(weights)%22%5D%0A%20%20%20%20%20%20%20%20%20%20T%20--%3E%20D%5B%22distribution%20over%20next%20token%3Cbr%2F%3Emat%200.62%20%C2%B7%20floor%200.21%20%C2%B7%20%E2%80%A6%22%5D%0A%20%20%20%20%20%20%20%20%20%20D%20--%3E%7Csample%7C%20N%5B%22mat%22%5D%0A%20%20%20%20%20%20%20%20%20%20N%20--%3E%7Cappend%7C%20P%0A%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.vstack(%5Bmo.md(r%22%22%22%0A%20%20%20%20%23%23%200.3%20What%20is%20an%20agent%3F%0A%0A%20%20%20%20Model%20%2B%20tool%20calls%2C%20in%20a%20loop.%0A%20%20%20%20%22%22%22)%2C%20mo.image(mo.notebook_dir()%20%2F%20%22public%2Fagents-meme.jpg%22%2C%20width%3D720)%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.vstack(%5Bmo.md(r%22%22%22%0A%20%20%20%20%23%23%200.4%20What%20is%20a%20harness%3F%0A%0A%20%20%20%20Different%20ways%20of%20implementing%20agents%3B%20mainly%20just%20a%20system%20prompt%2C%20model%20loop%2C%20and%20tool%20implementations.%0A%20%20%20%20%22%22%22)%2C%20mo.image(mo.notebook_dir()%20%2F%20%22public%2Fjson-meme.jpeg%22%2C%20width%3D560)%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(task)%3A%0A%20%20%20%20task(r%22%22%22%0A%20%20%20%20%23%23%200.5%20What%20do%20you%20need%3F%0A%0A%20%20%20%20-%20%60ollama%60%2C%20%60uv%60%2C%20%60git%60%2C%20%60gh%60%20(run%20%60gh%20auth%20login%60)%2C%20%60node%60%20%E2%89%A5%2020%0A%20%20%20%20-%20%60git%20clone%20https%3A%2F%2Fgithub.com%2FAr4l%2Flocal-agent-workshop%20%26%26%20cd%20local-agent-workshop%60%0A%20%20%20%20-%20%60uv%20run%20marimo%20edit%20notebook.py%60%0A%0A%20%20%20%20%60%60%60bash%0A%20%20%20%20brew%20install%20ollama%20uv%20gh%20node%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20macOS%0A%20%20%20%20winget%20install%20Ollama.Ollama%20astral-sh.uv%20GitHub.cli%20OpenJS.NodeJS.LTS%20Git.Git%20%20%20%23%20Windows%0A%20%20%20%20%23%20Linux%3A%20see%20README.md%0A%20%20%20%20%60%60%60%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%201.%20LLM%20inference%0A%0A%20%20%20%20Generate%20text%20using%20model%20weights%2C%20a%20large%20set%20of%20numbers.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(ARGS%2C%20mo%2C%20task)%3A%0A%20%20%20%20model_ui%20%3D%20mo.ui.dropdown(%0A%20%20%20%20%20%20%20%20options%3D%5B%22qwen3.5%3A4b%22%2C%20%22gemma4%3Ae4b-it-qat%22%2C%20%22gemma4%3A12b%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22qwen3.8%3A27b%22%2C%20%22qwen3.5%3A9b%22%5D%2C%0A%20%20%20%20%20%20%20%20value%3DARGS.get(%22model%22)%20or%20%22qwen3.5%3A4b%22%2C%20label%3D%22model%22)%0A%20%20%20%20mo.vstack(%5Btask(r%22%22%22%0A%20%20%20%20%23%23%201.1%20Choose%20a%20model%20for%20your%20RAM%0A%0A%20%20%20%20%7C%20RAM%20%7C%20model%20%7C%20download%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%208%20GB%20%7C%20%60qwen3.5%3A4b%60%20(or%20%60gemma4%3Ae4b-it-qat%60)%20%7C%203.4%20GB%20%7C%0A%20%20%20%20%7C%2016%20GB%20%7C%20%60gemma4%3A12b%60%20%7C%207.4%20GB%20%7C%0A%20%20%20%20%7C%2032%20GB%20%7C%20%60qwen3.8%3A27b%60%20%7C%2017%20GB%20%7C%0A%0A%20%20%20%20-%20Pull%20it%20yourself%20in%20a%20terminal%20now%3A%20the%20notebook%20never%20downloads%20models%0A%20%20%20%20-%20Ollama%20must%20be%20running%3A%20the%20macOS%2FWindows%20app%20starts%20it%2C%20on%20Linux%20run%20%60ollama%20serve%60%0A%20%20%20%20-%20Then%20pick%20the%20same%20model%20in%20the%20dropdown%20below%0A%0A%20%20%20%20%60%60%60bash%0A%20%20%20%20ollama%20pull%20qwen3.5%3A4b%20%20%20%20%20%20%23%20pick%20yours%20from%20the%20table%0A%20%20%20%20%60%60%60%0A%20%20%20%20%22%22%22)%2C%20model_ui%5D)%0A%20%20%20%20return%20(model_ui%2C)%0A%0A%0A%40app.cell%0Adef%20_(ARGS%2C%20model_ui)%3A%0A%20%20%20%20MODEL%20%3D%20ARGS.get(%22model%22)%20or%20model_ui.value%0A%20%20%20%20OPTIONS%20%3D%20%7B%22num_ctx%22%3A%2032768%7D%20%20%20%23%20Ollama%20defaults%20to%204k%20tokens%20on%20%3C24%20GiB%20GPUs%3A%20an%20agent%20overflows%20that%20fast%0A%20%20%20%20return%20MODEL%2C%20OPTIONS%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(MODEL%2C%20mo%2C%20ollama)%3A%0A%20%20%20%20mo.stop(not%20mo.running_in_notebook())%20%20%20%23%20preflight%20only%20matters%20in%20the%20notebook%0A%20%20%20%20import%20httpx%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20ollama.show(MODEL)%0A%20%20%20%20%20%20%20%20_status%20%3D%20mo.md(f%22%E2%9C%85%20%60%7BMODEL%7D%60%20is%20available%22)%0A%20%20%20%20except%20ollama.ResponseError%20as%20_e%3A%0A%20%20%20%20%20%20%20%20if%20_e.status_code%20!%3D%20404%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20raise%0A%20%20%20%20%20%20%20%20_status%20%3D%20mo.callout(mo.md(f%22Model%20%60%7BMODEL%7D%60%20is%20not%20downloaded.%20Run%20in%20a%20terminal%3A%5Cn%5Cn%60%60%60bash%5Cnollama%20pull%20%7BMODEL%7D%5Cn%60%60%60%22)%2C%20kind%3D%22danger%22)%0A%20%20%20%20except%20(ConnectionError%2C%20httpx.ConnectError)%3A%0A%20%20%20%20%20%20%20%20_status%20%3D%20mo.callout(mo.md(%22Ollama%20is%20not%20running.%20Start%20the%20Ollama%20app%20(macOS%2FWindows)%20or%20run%20%60ollama%20serve%60%20(Linux)%2C%20then%20re-run%20this%20cell.%22)%2C%20kind%3D%22danger%22)%0A%20%20%20%20_status%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.vstack(%5Bmo.md(r%22%22%22%0A%20%20%20%20%23%23%201.2%20While%20that%20downloads%3A%20what%20is%20an%20inference%20server%3F%0A%0A%20%20%20%20-%20It%20loads%20weights%20onto%20the%20GPU%20once%2C%20then%20answers%20HTTP%20requests%0A%20%20%20%20-%20Ollama%20provides%20pull%2C%20run%20and%20API%20commands.%20It%20launches%20llama.cpp's%20%60llama-server%60%0A%20%20%20%20-%20Ollama%20defaults%20to%20a%204k%20context%20on%20small%20GPUs.%20Agents%20need%20%60num_ctx%60%20%E2%89%A5%2016k%0A%20%20%20%20%22%22%22)%2C%20mo.hstack(%5Bmo.md(r%22%22%22%0A%20%20%20%20%7C%20%7C%20Ollama%20%7C%20llama.cpp%20(%60llama-server%60)%20%7C%20DwarfStar%20(%60antirez%2Fds4%60)%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%20what%20%7C%20Docker-for-models%3A%20pull%2C%20run%2C%20one%20local%20API%20%7C%20the%20engine%20itself%2C%20every%20knob%20exposed%20%7C%20one-model-class%20C%20engine%20by%20the%20Redis%20author%20%7C%0A%20%20%20%20%7C%20run%20%7C%20%60ollama%20run%20qwen3.5%3A9b%60%20%7C%20%60llama-server%20-hf%20ggml-org%2F%E2%80%A6-GGUF%60%20%7C%20%60.%2Fds4-server%20--ctx%2032768%60%20%7C%0A%20%20%20%20%7C%20hardware%20%7C%20Metal%2C%20CUDA%2C%20ROCm%2C%20Vulkan%2C%20CPU%20%7C%20same%20%2B%20SYCL%2C%20OpenCL%2C%20RPC%20%E2%80%A6%20%7C%2096%20GB%20Macs%2C%20CUDA%2C%20ROCm%20%7C%0A%20%20%20%20%22%22%22)%2C%20mo.image(mo.notebook_dir()%20%2F%20%22public%2Finference-meme.png%22%2C%20width%3D300)%5D%2C%20widths%3D%5B3%2C%201%5D%2C%20align%3D%22start%22)%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%201.3%20Four%20API%20shapes%2C%20one%20model%0A%0A%20%20%20%20-%20%60%2Fapi%2Fchat%60%20is%20Ollama's%2C%20%60%2Fv1%2Fchat%2Fcompletions%60%20and%20%60%2Fv1%2Fresponses%60%20OpenAI's%2C%20%60%2Fv1%2Fmessages%60%20Anthropic's%0A%20%20%20%20-%20Existing%20clients%20like%20OpenAI%20SDK%2C%20Claude%20Code%20and%20Codex%20can%20use%20a%20local%20model%0A%20%20%20%20-%20The%20same%20prompt%20produced%20the%20same%20tool%20call.%20Only%20the%20JSON%20envelope%20differed%0A%0A%20%20%20%20%7C%20endpoint%20%7C%20tool%20call%20lives%20in%20%7C%20thinking%20lives%20in%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%20%60POST%20%2Fapi%2Fchat%60%20%7C%20%60message.tool_calls%5B%5D.function.%7Bname%2C%20arguments%3A%20object%7D%60%20%7C%20%60message.thinking%60%20%7C%0A%20%20%20%20%7C%20%60POST%20%2Fv1%2Fchat%2Fcompletions%60%20%7C%20%60choices%5B0%5D.message.tool_calls%5B%5D.function.arguments%60%20(JSON%20**string**)%20%7C%20%60message.reasoning%60%20%7C%0A%20%20%20%20%7C%20%60POST%20%2Fv1%2Fresponses%60%20%7C%20%60output%5B%5D%60%20item%20%60type%3A%20%22function_call%22%60%20%7C%20%60output%5B%5D%60%20item%20%60type%3A%20%22reasoning%22%60%20%7C%0A%20%20%20%20%7C%20%60POST%20%2Fv1%2Fmessages%60%20%7C%20%60content%5B%5D%60%20block%20%60type%3A%20%22tool_use%22%60%2C%20%60input%3A%20object%60%20%7C%20%60content%5B%5D%60%20block%20%60type%3A%20%22thinking%22%60%20%7C%0A%0A%20%20%20%20We%20use%20%60%2Fapi%2Fchat%60%20through%20the%20%60ollama%60%20Python%20package%20because%20only%20it%20accepts%20%60num_ctx%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(task)%3A%0A%20%20%20%20task(r%22%22%22%0A%20%20%20%20%23%23%201.4%20Your%20first%20local%20chat%0A%0A%20%20%20%20-%20Implement%20%60chat(messages%2C%20tools)%60%3A%20call%20%60ollama.chat%60%20once%20and%20return%20%60.message%60%0A%20%20%20%20-%20Pass%20%60MODEL%60%20and%20%60OPTIONS%60.%20The%20message%20contains%20%60.content%60%2C%20%60.thinking%60%20and%20%60.tool_calls%60%0A%20%20%20%20-%20Run%20the%20next%20cell%20and%20read%20the%20thinking%20trace%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(MODEL%2C%20OPTIONS%2C%20ollama)%3A%0A%20%20%20%20def%20chat(messages%2C%20tools%3DNone)%3A%0A%20%20%20%20%20%20%20%20%22%22%22One%20model%20call.%20Returns%20the%20assistant%20message%20(content%2C%20thinking%2C%20tool_calls).%22%22%22%0A%20%20%20%20%20%20%20%20%23%20---%20solution%3A%20chat%20---%0A%20%20%20%20%20%20%20%20return%20ollama.chat(MODEL%2C%20messages%3Dmessages%2C%20tools%3Dtools%2C%20options%3DOPTIONS).message%0A%20%20%20%20%20%20%20%20%23%20---%20end%20solution%20---%0A%20%20%20%20return%20(chat%2C)%0A%0A%0A%40app.cell%0Adef%20_(chat%2C%20mo%2C%20trace)%3A%0A%20%20%20%20mo.stop(not%20mo.running_in_notebook())%20%20%20%23%20skip%20this%20demo%20when%20run%20as%20a%20script%0A%20%20%20%20_reply%20%3D%20chat(%5B%7B%22role%22%3A%20%22user%22%2C%20%22content%22%3A%20%22In%20one%20sentence%3A%20what%20is%20a%20tool%20call%3F%22%7D%5D)%0A%20%20%20%20trace.thinking(_reply.thinking)%0A%20%20%20%20trace.assistant(_reply.content)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%202.%20Tool%20calling%0A%0A%20%20%20%20%23%23%202.0%20A%20tool%20call%20is%20just%20text%0A%0A%20%20%20%20-%20The%20model%20emits%20the%20tags%20it%20was%20trained%20on.%20The%20server%20parses%20them%20into%20JSON%0A%20%20%20%20-%20Qwen3.5%20writes%20%60%3Ctool_call%3E%3Cfunction%3Drun_shell%3E%3Cparameter%3Dcommand%3E%60.%20Ollama%20returns%20%60tool_calls%60%0A%20%20%20%20-%20Your%20program%20decides%20whether%20to%20run%20it.%20Valid%20syntax%20does%20not%20grant%20permission%0A%0A%20%20%20%20%60%60%60text%0A%20%20%20%20%3Cthink%3EThe%20user%20wants%20to%20list%20files.%20I'll%20use%20run_shell.%3C%2Fthink%3E%0A%20%20%20%20%3Ctool_call%3E%0A%20%20%20%20%3Cfunction%3Drun_shell%3E%0A%20%20%20%20%3Cparameter%3Dcommand%3E%0A%20%20%20%20ls%20-la%0A%20%20%20%20%3C%2Fparameter%3E%0A%20%20%20%20%3C%2Ffunction%3E%0A%20%20%20%20%3C%2Ftool_call%3E%0A%20%20%20%20%60%60%60%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(task)%3A%0A%20%20%20%20task(r%22%22%22%0A%20%20%20%20%23%23%202.1%20Tool%20number%20one%3A%20%60run_shell%60%0A%0A%20%20%20%20-%20Implement%20%60run_shell(command%3A%20str)%20-%3E%20str%60%3A%20run%20%60subprocess.run%60%20in%20%60workshop.workdir()%60%2C%20then%20return%20output%20and%20exit%20code%0A%20%20%20%20-%20Always%20return%20a%20string.%20Never%20raise%20because%20errors%20inform%20the%20model%0A%20%20%20%20-%20The%20model%20sees%20the%20docstring%20as%20its%20schema.%20Run%20the%20next%20cell%20to%20inspect%20it%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(subprocess%2C%20workshop)%3A%0A%20%20%20%20DENY%20%3D%20(%22rm%20-rf%22%2C%20%22sudo%22%2C%20%22curl%22%2C%20%22wget%22%2C%20%22git%20%22)%0A%0A%20%20%20%20def%20run_shell(command%3A%20str)%20-%3E%20str%3A%0A%20%20%20%20%20%20%20%20%22%22%22Run%20a%20shell%20command%20in%20the%20repo%20root%20and%20return%20its%20output%20and%20exit%20code.%0A%0A%20%20%20%20%20%20%20%20Args%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20command%3A%20the%20command%20to%20run%2C%20e.g.%20%60node%20--check%20app.js%60%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%23%20---%20solution%3A%20run_shell%20---%0A%20%20%20%20%20%20%20%20if%20any(bad%20in%20command%20for%20bad%20in%20DENY)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20f%22BLOCKED%3A%20%7Bcommand!r%7D%20is%20not%20allowed%22%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20p%20%3D%20subprocess.run(command%2C%20shell%3DTrue%2C%20cwd%3Dworkshop.workdir()%2C%20timeout%3D60%2C%20text%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20stdout%3Dsubprocess.PIPE%2C%20stderr%3Dsubprocess.STDOUT)%0A%20%20%20%20%20%20%20%20except%20subprocess.TimeoutExpired%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20%22ERROR%3A%20timed%20out%20after%2060%20s%22%0A%20%20%20%20%20%20%20%20return%20f%22%7Bp.stdout%5B-4000%3A%5D%7D%5Cn%5Bexit%20code%20%7Bp.returncode%7D%5D%22%0A%20%20%20%20%20%20%20%20%23%20---%20end%20solution%20---%0A%0A%20%20%20%20SHELL_TOOLS%20%3D%20%7B%22run_shell%22%3A%20(workshop.schema_of(run_shell)%2C%20run_shell)%7D%0A%20%20%20%20return%20(SHELL_TOOLS%2C)%0A%0A%0A%40app.cell%0Adef%20_(SHELL_TOOLS%2C%20mo)%3A%0A%20%20%20%20mo.vstack(%5Bmo.md(%22%23%23%202.1%20The%20schema%20the%20model%20sees%5Cn%5CnThis%20is%20everything%20the%20model%20knows%20about%20your%20tool%3A%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.json(SHELL_TOOLS%5B%22run_shell%22%5D%5B0%5D)%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(task)%3A%0A%20%20%20%20task(r%22%22%22%0A%20%20%20%20%23%23%202.2%20The%20loop%0A%0A%20%20%20%20-%20%60execute(call%2C%20tools)%60%3A%20find%20the%20name%2C%20call%20it%20with%20%60**arguments%60%2C%20return%20a%20string%2C%20cap%20its%20length%0A%20%20%20%20-%20%60agent_loop(messages%2C%20tools)%60%3A%20chat%2C%20append%20reply%2C%20run%20tool%20calls%2C%20append%20results%20and%20repeat%0A%20%20%20%20-%20Stop%20when%20the%20reply%20has%20no%20tool%20calls%2C%20or%20after%20%60max_turns%60.%20Return%20the%20reason%0A%0A%20%20%20%20%60%60%60text%0A%20%20%20%20for%20turn%20in%20range(max_turns)%3A%0A%20%20%20%20%20%20%20%20reply%20%3D%20chat(messages%2C%20schemas)%3B%20%20messages.append(reply)%0A%20%20%20%20%20%20%20%20if%20not%20reply.tool_calls%3A%20return%20%22stopped%22%0A%20%20%20%20%20%20%20%20for%20call%20in%20reply.tool_calls%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20messages.append(%7B%22role%22%3A%20%22tool%22%2C%20%22tool_name%22%3A%20call.function.name%2C%20%22content%22%3A%20execute(call%2C%20tools)%7D)%0A%20%20%20%20return%20%22max_turns%22%0A%20%20%20%20%60%60%60%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(chat%2C%20trace)%3A%0A%20%20%20%20def%20execute(call%2C%20tools)%20-%3E%20str%3A%0A%20%20%20%20%20%20%20%20%22%22%22Run%20one%20tool%20call.%20Always%20returns%20a%20string%3A%20errors%20are%20for%20the%20model%20to%20read.%22%22%22%0A%20%20%20%20%20%20%20%20%23%20---%20solution%3A%20execute%20---%0A%20%20%20%20%20%20%20%20name%2C%20args%20%3D%20call.function.name%2C%20dict(call.function.arguments%20or%20%7B%7D)%0A%20%20%20%20%20%20%20%20if%20name%20not%20in%20tools%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20f%22ERROR%3A%20unknown%20tool%20%7Bname!r%7D%3B%20available%3A%20%7Bsorted(tools)%7D%22%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20result%20%3D%20str(tools%5Bname%5D%5B1%5D(**args))%0A%20%20%20%20%20%20%20%20except%20Exception%20as%20e%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20f%22ERROR%3A%20%7Btype(e).__name__%7D%3A%20%7Be%7D%22%0A%20%20%20%20%20%20%20%20if%20len(result)%20%3E%208000%3A%20%20%23%20tool%20output%20eats%20context%3A%20keep%20the%20head%2C%20tell%20the%20model%0A%20%20%20%20%20%20%20%20%20%20%20%20result%20%3D%20result%5B%3A8000%5D%20%2B%20f%22%5Cn%E2%80%A6%20%5B%7Blen(result)%20-%208000%7D%20more%20chars%20cut%3B%20read%20smaller%20ranges%5D%22%0A%20%20%20%20%20%20%20%20return%20result%0A%20%20%20%20%20%20%20%20%23%20---%20end%20solution%20---%0A%0A%20%20%20%20def%20agent_loop(messages%2C%20tools%2C%20max_turns%3D25)%20-%3E%20str%3A%0A%20%20%20%20%20%20%20%20%22%22%22Call%20the%20model%20until%20it%20answers%20without%20tool%20calls%20(or%20the%20turn%20budget%20runs%20out).%22%22%22%0A%20%20%20%20%20%20%20%20%23%20---%20solution%3A%20agent_loop%20---%0A%20%20%20%20%20%20%20%20schemas%20%3D%20%5Bschema%20for%20schema%2C%20_fn%20in%20tools.values()%5D%0A%20%20%20%20%20%20%20%20for%20turn%20in%20range(max_turns)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20trace.rule(f%22turn%20%7Bturn%20%2B%201%7D%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20reply%20%3D%20chat(messages%2C%20schemas)%0A%20%20%20%20%20%20%20%20%20%20%20%20messages.append(reply)%0A%20%20%20%20%20%20%20%20%20%20%20%20trace.thinking(reply.thinking)%0A%20%20%20%20%20%20%20%20%20%20%20%20trace.assistant(reply.content)%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20not%20reply.tool_calls%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20%22stopped%22%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20call%20in%20reply.tool_calls%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20trace.tool_call(call.function.name%2C%20dict(call.function.arguments%20or%20%7B%7D))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20result%20%3D%20execute(call%2C%20tools)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20trace.tool_result(result)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20messages.append(%7B%22role%22%3A%20%22tool%22%2C%20%22tool_name%22%3A%20call.function.name%2C%20%22content%22%3A%20result%7D)%0A%20%20%20%20%20%20%20%20return%20%22max_turns%22%0A%20%20%20%20%20%20%20%20%23%20---%20end%20solution%20---%0A%20%20%20%20return%20(agent_loop%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(task)%3A%0A%20%20%20%20task(r%22%22%22%0A%20%20%20%20%23%23%202.3%20Try%20it%20on%20a%20real%20repo%0A%0A%20%20%20%20-%20The%20next%20cell%20clones%20%60Ar4l%2Fsimple-todo-app%60%20and%20forks%20it%20under%20your%20account%0A%20%20%20%20-%20Ask%3A%20%22How%20many%20lines%20does%20app.js%20have%2C%20and%20which%20function%20deletes%20a%20todo%3F%22%0A%20%20%20%20-%20Read%20the%20trace.%20Did%20it%20call%20the%20tool%20or%20guess%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(WORK%2C%20harness%2C%20mo)%3A%0A%20%20%20%20REPO_DIR%20%3D%20harness.prepare_repo(%22Ar4l%2Fsimple-todo-app%22%2C%20WORK)%0A%20%20%20%20question_ui%20%3D%20mo.ui.text(value%3D%22How%20many%20lines%20does%20app.js%20have%2C%20and%20which%20function%20deletes%20a%20todo%3F%22%2C%20full_width%3DTrue)%0A%20%20%20%20ask_ui%20%3D%20mo.ui.run_button(label%3D%22Ask%20the%20agent%22)%0A%20%20%20%20_rel%20%3D%20REPO_DIR.relative_to(mo.notebook_dir())%20if%20REPO_DIR.is_relative_to(mo.notebook_dir())%20else%20REPO_DIR%0A%20%20%20%20mo.vstack(%5Bmo.md(f%22%23%23%202.3%20Ask%20the%20agent%5Cn%5Cnworking%20directory%3A%20%60%7B_rel%7D%60%22)%2C%20question_ui%2C%20ask_ui%5D)%0A%20%20%20%20return%20REPO_DIR%2C%20ask_ui%2C%20question_ui%0A%0A%0A%40app.cell%0Adef%20_(SHELL_TOOLS%2C%20agent_loop%2C%20ask_ui%2C%20mo%2C%20question_ui)%3A%0A%20%20%20%20mo.stop(not%20ask_ui.value%2C%20mo.md(%22*press%20**Ask%20the%20agent**%20first*%22))%0A%20%20%20%20_messages%20%3D%20%5B%7B%22role%22%3A%20%22system%22%2C%20%22content%22%3A%20%22You%20answer%20questions%20about%20the%20repo%20in%20the%20working%20directory%20using%20run_shell.%20Paths%20are%20relative%20to%20the%20repo%20root%3B%20never%20use%20cd.%22%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%22role%22%3A%20%22user%22%2C%20%22content%22%3A%20question_ui.value%7D%5D%0A%20%20%20%20agent_loop(_messages%2C%20SHELL_TOOLS)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%202.4%20Do%20special%20tool%20tokens%20matter%3F%0A%0A%20%20%20%20-%20Every%20vendor%20uses%20different%20tags%3A%20%60%3Ctool_call%3E%60%2C%20%60%5BTOOL_CALLS%5D%60%2C%20%60%3C%7CDSML%7C%3E%60.%20Parsers%20lag%20months%20behind%0A%20%20%20%20-%20No%20vendor%20publishes%20an%20ablation.%20One%20internal%20controlled%20run%20found%20BFCL%20%E2%88%920.8%20to%20%2B1.6%20points%0A%20%20%20%20-%20Training%20on%20many%20formats%20and%20using%20fewer%20atomic%20tools%20made%20the%20difference%0A%0A%20%20%20%20%7C%20family%20%7C%20delimiter%20%7C%20argument%20encoding%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%20Qwen3.5%20%2F%20Qwen3-Coder%20%7C%20%60%3Ctool_call%3E%3Cfunction%3D%E2%80%A6%3E%3Cparameter%3D%E2%80%A6%3E%60%20%7C%20XML%20per%20argument%2C%20raw%20strings%20%7C%0A%20%20%20%20%7C%20DeepSeek%20V3.2%20%2F%20V4%20%7C%20%60%3C%EF%BD%9CDSML%EF%BD%9Cinvoke%20name%3D%E2%80%A6%3E%60%20%7C%20XML%20per%20argument%20%7C%0A%20%20%20%20%7C%20Gemma%204%20%7C%20%60%3C%EF%BD%9Ctool_call%3Ecall%3ANAME%7B%E2%80%A6%7D%3Ctool_call%EF%BD%9C%3E%60%20%7C%20key%3Avalue%2C%20quote%20token%20%7C%0A%20%20%20%20%7C%20Mistral%20%7C%20%60%5BTOOL_CALLS%5D%60%20name%20%60%5BARGS%5D%60%20json%20%7C%20JSON%20%7C%0A%20%20%20%20%7C%20Hermes%2C%20Granite%204%2C%20Mellum2%20%7C%20%60%3Ctool_call%3E%7B%E2%80%A6%7D%3C%2Ftool_call%3E%60%20%7C%20JSON%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%202.5%20Small-model%20realities%0A%0A%20%20%20%20-%20Keep%203%E2%80%935%20atomic%20tools%20in%20context%20to%20improve%20tool%20choice%0A%20%20%20%20-%20Thinking%20improves%20small-model%20tool%20use%20by%20%2B9%20to%20%2B12%20BFCL%20Live%20points%20for%20Qwen3%204B%2F8B%0A%20%20%20%20-%20Never%20combine%20JSON%20%60format%3D%60%20with%20%60tools%3D%60.%20The%20grammar%20mask%20cannot%20emit%20%60%3Ctool_call%3E%60%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%20%20%20%20%23%203.%20Model%20Context%20Protocol%0A%0A%20%20%20%20%20%20%20%20A%20server%20(local%20or%20remote)%20uses%20MCP%20to%20expose%20tools%20and%20data%20to%20agents.%0A%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%20%20%20%20mo.mermaid(%22%22%22%0A%20%20%20%20%20%20%20%20sequenceDiagram%0A%20%20%20%20%20%20%20%20%20%20participant%20S%20as%20MCP%20server%0A%20%20%20%20%20%20%20%20%20%20participant%20H%20as%20agent%20host%20(your%20loop)%0A%20%20%20%20%20%20%20%20%20%20participant%20M%20as%20model%0A%20%20%20%20%20%20%20%20%20%20S-%3E%3EH%3A%20list_tools%20%E2%86%92%20name%2C%20description%2C%20inputSchema%0A%20%20%20%20%20%20%20%20%20%20H-%3E%3EM%3A%20tool%20schemas%20%2B%20messages%0A%20%20%20%20%20%20%20%20%20%20M-%3E%3EH%3A%20tool%20call%20(name%2C%20arguments)%0A%20%20%20%20%20%20%20%20%20%20H-%3E%3ES%3A%20call_tool(name%2C%20arguments)%0A%20%20%20%20%20%20%20%20%20%20S-%3E%3EH%3A%20result%20text%0A%20%20%20%20%20%20%20%20%20%20H-%3E%3EM%3A%20role%3Dtool%20message%0A%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%203.1%20MCP%20or%20CLI%3F%0A%0A%20%20%20%20-%20GitHub%20work%20does%20not%20require%20MCP.%20Scaffolding%2C%20not%20interface%2C%20drives%20token%20cost%20%5B%5Econtrolled_mcp%5D%0A%20%20%20%20-%20Structured%20atomic%20edit%20tools%20reduce%20execution%20errors%20and%20improve%20consistency%2C%20especially%20for%20weaker%20models%20%5B%5Einterface_mcp%5D%0A%20%20%20%20-%20Fewer%20tools%20in%20context%20improves%20tool%20choice%3A%2093%25%20at%20~2%20tools%20vs%2087%25%20at%205%20%5B%5Einterface_mcp_2%5D%0A%0A%20%20%20%20Choose%20MCP%20for%20remote%20services%2C%20delegated%20authorization%20(OAuth%202.1)%20and%20hosts%20without%20a%20shell%20%5B%5Emcp_spec%5D.%0A%0A%20%20%20%20%5B%5Econtrolled_mcp%5D%3A%20https%3A%2F%2Farxiv.org%2Fabs%2F2608.08654%0A%20%20%20%20%5B%5Einterface_mcp%5D%3A%20https%3A%2F%2Farxiv.org%2Fabs%2F2608.11386%0A%20%20%20%20%5B%5Einterface_mcp_2%5D%3A%20https%3A%2F%2Farxiv.org%2Fabs%2F2605.24660%0A%20%20%20%20%5B%5Emcp_spec%5D%3A%20https%3A%2F%2Fmodelcontextprotocol.io%2Fspecification%2F2026-07-28%2Fbasic%2Fauthorization%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(task)%3A%0A%20%20%20%20task(r%22%22%22%0A%20%20%20%20%23%23%203.2%20Plug%20an%20MCP%20server%20into%20your%20loop%0A%0A%20%20%20%20-%20%60workshop%2Fmcp_server.py%60%20provides%20%60read_file%60%2C%20%60write_file%60%20and%20%60edit_file%60%2C%20restricted%20to%20the%20repo%0A%20%20%20%20-%20Start%20it%20with%20%60McpSource(%5B...%5D)%60%2C%20then%20create%20%60FILE_TOOLS%60%20from%20%60src.tools%60%0A%20%20%20%20-%20Build%20each%20entry%20as%20%60(to_ollama_tool(t)%2C%20(lambda%20name%3A%20lambda%20**args%3A%20src.call(name%2C%20args))(t.name))%60%3A%20a%20plain%20lambda%20would%20late-bind%20%60t%60%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(McpSource%2C%20REPO_DIR%2C%20mo%2C%20sys%2C%20to_ollama_tool)%3A%0A%20%20%20%20src%20%3D%20McpSource(%5Bsys.executable%2C%20str(mo.notebook_dir()%20%2F%20%22workshop%22%20%2F%20%22mcp_server.py%22)%2C%20str(REPO_DIR)%5D)%0A%0A%20%20%20%20%23%20---%20solution%3A%20mcp%20---%0A%20%20%20%20FILE_TOOLS%20%3D%20%7Bt.name%3A%20(to_ollama_tool(t)%2C%20(lambda%20name%3A%20lambda%20**args%3A%20src.call(name%2C%20args))(t.name))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20t%20in%20src.tools%7D%0A%20%20%20%20%23%20---%20end%20solution%20---%0A%20%20%20%20mo.md(%22%23%23%203.2%20Tools%20from%20the%20MCP%20server%5Cn%5Cn%22%20%2B%20(%22MCP%20server%20exposes%3A%20%22%20%2B%20%22%2C%20%22.join(f%22%60%7Bn%7D%60%22%20for%20n%20in%20FILE_TOOLS)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20FILE_TOOLS%20else%20%22nothing%20registered%20yet%3A%20fill%20in%20the%20TODO%20in%20this%20cell%22))%0A%20%20%20%20return%20(FILE_TOOLS%2C)%0A%0A%0A%40app.cell%0Adef%20_(FILE_TOOLS%2C%20SHELL_TOOLS)%3A%0A%20%20%20%20TOOLS%20%3D%20SHELL_TOOLS%20%7C%20FILE_TOOLS%0A%20%20%20%20return%20(TOOLS%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%20%20%20%20%23%204.%20Fixing%20a%20GitHub%20issue%20end%20to%20end%0A%0A%20%20%20%20%20%20%20%20-%20The%20model%20receives%20the%20issue%20text%20and%20four%20tools.%20The%20harness%20handles%20everything%20else%0A%20%20%20%20%20%20%20%20-%20When%20the%20model%20stops%2C%20the%20harness%20commits%20the%20diff%20and%20opens%20a%20draft%20PR%0A%20%20%20%20%20%20%20%20-%20Nothing%20is%20tested%20automatically.%20A%20human%20reviews%20the%20PR%2C%20as%20with%20any%20coding%20agent%0A%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%20%20%20%20mo.mermaid(%22%22%22%0A%20%20%20%20%20%20%20%20flowchart%20LR%0A%20%20%20%20%20%20%20%20%20%20I%5B%22issue%20URL%22%5D%20--%3E%20C%5B%22harness%3A%20fork%2C%20clone%2C%20branch%22%5D%0A%20%20%20%20%20%20%20%20%20%20C%20--%3E%20L%5B%22agent_loop%3Cbr%2F%3E(model%20%2B%204%20tools)%22%5D%0A%20%20%20%20%20%20%20%20%20%20L%20--%3E%20D%7B%22any%20file%20changed%3F%22%7D%0A%20%20%20%20%20%20%20%20%20%20D%20--%3E%7Cno%7C%20X%5B%22nothing%20pushed%22%5D%0A%20%20%20%20%20%20%20%20%20%20D%20--%3E%7Cyes%7C%20P%5B%22commit%20%C2%B7%20push%20%C2%B7%20draft%20PR%22%5D%0A%20%20%20%20%20%20%20%20%20%20P%20--%3E%20H%5B%22human%20review%22%5D%0A%20%20%20%20%20%20%20%20%22%22%22)%2C%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(task)%3A%0A%20%20%20%20task(r%22%22%22%0A%20%20%20%20%23%23%204.1%20Run%20it%0A%0A%20%20%20%20-%20Pick%20an%20issue%20and%20run%20it.%20Watch%20the%20trace%2C%20then%20open%20its%20PR%0A%20%20%20%20-%20Or%20run%3A%20%60uv%20run%20agent.py%20--%20--issue%20%3Curl%3E%20--model%20qwen3.5%3A4b%60%0A%20%20%20%20-%20Issue%201%20fixes%20a%20bug.%20Issues%202%20and%203%20add%20features.%20Try%201%20first%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%204.2%20What%20to%20expect%20(15%20runs%2C%2032k%20context%2C%20no%20gate)%0A%0A%20%20%20%20-%20Every%20model%20that%20calls%20tools%20fixes%20the%20bug%20issue%20in%20under%205%20minutes%0A%20%20%20%20-%20Only%20the%2027B%20passes%20issue%203%20and%20keeps%20existing%20behaviour%20intact%20on%20all%20three%0A%20%20%20%20-%20Small%20models%20ship%20plausible%20PRs%20fast%20and%20quietly%20break%20features%3A%20review%20the%20diff%0A%0A%20%20%20%20%7C%20tier%20%7C%20model%20%7C%20memory%20%7C%201%3A%20bug%20%7C%202%3A%20description%20%7C%203%3A%20due%20date%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%2032%20GB%20%7C%20%60qwen3.8%3A27b%60%20%7C%2018%20GB%20%7C%20%E2%9C%85%201.5%20min%20%7C%20%E2%9C%85%207%20min%20%7C%20%E2%9C%85%207%20min%20%7C%0A%20%20%20%20%7C%2016%20GB%20%7C%20%60gemma4%3A12b%60%20%7C%208.4%20GB%20%7C%20%E2%9C%85%204.5%20min%20%7C%20%E2%9C%85%2018%20min%20%7C%20%E2%9C%97%20silent%2C%20killed%20at%2025%20min%20%7C%0A%20%20%20%20%7C%208%20GB%20%7C%20%60gemma4%3Ae4b-it-qat%60%20%7C%205.7%20GB%20%7C%20%E2%9C%85%201%20min%20%7C%20%E2%9C%85%20but%20broke%20Escape-to-cancel%20%7C%20%E2%9C%97%20half%20done%20%7C%0A%20%20%20%20%7C%208%20GB%20%7C%20%60qwen3.5%3A4b%60%20%7C%204.3%20GB%20%7C%20%E2%9C%85%2045%20s%20%7C%20partial%2C%2011%20min%20%7C%20%E2%9C%97%2025%20turns%2C%20broke%20add%2Fdelete%20%7C%0A%0A%20%20%20%20Most%20tool%20errors%20were%20%60edit_file%60%20with%20an%20%60old%60%20string%20that%20did%20not%20match%20the%20file%20verbatim.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(ARGS%2C%20mo)%3A%0A%20%20%20%20issue_ui%20%3D%20mo.ui.dropdown(%0A%20%20%20%20%20%20%20%20options%3D%5Bf%22https%3A%2F%2Fgithub.com%2FAr4l%2Fsimple-todo-app%2Fissues%2F%7Bi%7D%22%20for%20i%20in%20(1%2C%202%2C%203)%5D%2C%0A%20%20%20%20%20%20%20%20value%3DARGS.get(%22issue%22)%20or%20%22https%3A%2F%2Fgithub.com%2FAr4l%2Fsimple-todo-app%2Fissues%2F1%22%2C%20label%3D%22issue%22)%0A%20%20%20%20pr_ui%20%3D%20mo.ui.checkbox(value%3DTrue%2C%20label%3D%22open%20a%20draft%20PR%20when%20done%22)%0A%20%20%20%20run_ui%20%3D%20mo.ui.run_button(label%3D%22Run%20the%20agent%20on%20this%20issue%22)%0A%20%20%20%20mo.vstack(%5Bmo.md(%22%23%23%204.1%20Pick%20an%20issue%22)%2C%20mo.hstack(%5Bissue_ui%2C%20pr_ui%2C%20run_ui%5D%2C%20justify%3D%22start%22)%5D)%0A%20%20%20%20return%20issue_ui%2C%20pr_ui%2C%20run_ui%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20ARGS%2C%0A%20%20%20%20MODEL%2C%0A%20%20%20%20OPTIONS%2C%0A%20%20%20%20TOOLS%2C%0A%20%20%20%20WORK%2C%0A%20%20%20%20agent_loop%2C%0A%20%20%20%20harness%2C%0A%20%20%20%20issue_ui%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20pr_ui%2C%0A%20%20%20%20run_ui%2C%0A)%3A%0A%20%20%20%20mo.stop(not%20(run_ui.value%20or%20ARGS.get(%22issue%22))%2C%20mo.md(%22*press%20**Run%20the%20agent%20on%20this%20issue**%20first*%22))%0A%20%20%20%20result%20%3D%20harness.solve_issue(%0A%20%20%20%20%20%20%20%20ARGS.get(%22issue%22)%20or%20issue_ui.value%2C%20agent_loop%2C%20TOOLS%2C%0A%20%20%20%20%20%20%20%20model%3DMODEL%2C%20options%3DOPTIONS%2C%20root%3DWORK%2C%0A%20%20%20%20%20%20%20%20open_pr%3Dpr_ui.value%20and%20%22dry-run%22%20not%20in%20ARGS)%0A%20%20%20%20result%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%205.%20Ready%20harnesses%0A%0A%20%20%20%20-%20The%20same%20loop%2C%20with%20more%20polish%3A%20%60pi%60%20and%20DeepSeek's%20%60dsh%60%20add%20structured%20tools%2C%20sessions%20and%20compaction%0A%20%20%20%20-%20%60mini-swe-agent%60%20uses%20only%20bash%3A%20a%20190-line%20agent%20loop%2C%20near%20state%20of%20the%20art%20on%20SWE-bench%0A%20%20%20%20-%20DeepSeek's%20%60dsh%60%20uses%20%60pi%60's%20model%20layer.%20%60pi%60%20intentionally%20ships%20without%20MCP%0A%0A%20%20%20%20%7C%20%7C%20mini-swe-agent%20%7C%20pi%20%7C%20DeepSeek%20Harness%20(%60dsh%60)%20%7C%0A%20%20%20%20%7C%3A---%7C%3A---%7C%3A---%7C%3A---%7C%0A%20%20%20%20%7C%20language%20%7C%20Python%20%7C%20TypeScript%20%7C%20TypeScript%20%2B%20Python%20SDK%20%7C%0A%20%20%20%20%7C%20tools%20%7C%20bash%20only%20%7C%20read%2C%20bash%2C%20edit%2C%20write%2C%20grep%2C%20find%2C%20ls%20%7C%2017%20plugins%20%2B%20MCP%20client%20%7C%0A%20%20%20%20%7C%20agent%20loop%20%7C%20190%20lines%20%7C%20803%20lines%20%7C%202.4k%20lines%20%7C%0A%20%20%20%20%7C%20install%20%E2%86%92%20answer%20(%60qwen3.5%3A9b%60)%20%7C%208%20s%20%E2%86%92%2061%20s%2C%2010%20calls%20%7C%2019%20s%20%E2%86%92%209%20s%2C%201%20call%20%7C%203.5%20min%20%E2%86%92%2041%20s%2C%201%20call%20%7C%0A%20%20%20%20%7C%20Ollama%20config%20%7C%206-line%20YAML%20%7C%20%60~%2F.pi%2Fagent%2Fmodels.json%60%20%7C%20%60settings.yaml%60%20plugin%20composition%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(task)%3A%0A%20%20%20%20task(r%22%22%22%0A%20%20%20%20%23%23%205.1%20Try%20one%3A%20%60pi%60%0A%0A%20%20%20%20-%20Install%20it%2C%20connect%20it%20to%20Ollama%20and%20ask%20the%20question%20your%20loop%20answered%20in%202.3%0A%20%20%20%20-%20Compare%20its%20trace%20with%20yours.%20What%20did%20the%20harness%20add%3F%0A%20%20%20%20-%20Find%20configurations%20for%20all%20three%20in%20%60harnesses%2F%60%0A%0A%20%20%20%20%60%60%60bash%0A%20%20%20%20npm%20install%20-g%20%40earendil-works%2Fpi-coding-agent%0A%20%20%20%20mkdir%20-p%20~%2F.pi%2Fagent%20%26%26%20cp%20harnesses%2Fpi%2Fmodels.json%20~%2F.pi%2Fagent%2F%20%20%20%23%20edit%20the%20model%20id%0A%20%20%20%20cd%20work%2Fsimple-todo-app%20%26%26%20pi%20--provider%20ollama%20--model%20qwen3.5%3A9b%20-p%20%22How%20many%20lines%20does%20app.js%20have%3F%22%0A%20%20%20%20%60%60%60%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Takeaways%0A%0A%20%20%20%20-%20An%20agent%20is%20a%20loop%3A%20the%20model%20proposes%2C%20your%20code%20validates%20and%20executes%2C%20then%20returns%20results%0A%20%20%20%20-%20Small%20local%20models%20work%20with%20few%20tools%2C%20enough%20context%20and%20a%20human%20reviewing%20the%20PR%0A%20%20%20%20-%20MCP%20supplies%20tools%2C%20not%20intelligence.%20Harnesses%20provide%20prompts%2C%20loops%20and%20stop%20rules%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
aab5fb9fd74d5178aad24948f211c5e9