Dayward AIWeChat Mini Program
Build Your Own Coding Agent in 21 Days
Week 2 · D8🔒 LockedAbout 4 hours

Reference Injection: Parsing @ Files, Directories, URLs, and Images, and Accounting for What Got Injected

Don't make the agent scan the whole repo itself: implement @-reference syntax that parses files, directories, and web addresses into structured injected content, handle binary and oversized files, and print in the terminal exactly how many characters were injected and how much budget that used.

Today's goals 0/3

Sign in to tick these off and save your progress.

Today's Goals

  1. Implement parsing and expansion for a reference syntax covering files, directories, and URLs
  2. Set a budget for injected content, and prune it by an explainable rule when it goes over
  3. Explain the trade-off between proactive injection and letting the model call a tool to retrieve it itself

Week two starts today, and the theme shifts from "can it work" to "can it avoid detours." When you finish, scroll back up and tick the three goals off.

Plain-Language Walkthrough

Pointing the way: putting the documents on their desk beats making them search the building

Week one's new hire can work now. But notice how they start every time: search the repository for a keyword, list a directory, open three or four files, and only then begin.

And very often you knew which file mattered all along. You simply did not say.

The first seven days' mca was like that. Ask "what is wrong with divide" and it will glob for files, grep for keywords, read_file to read — three or four tool calls, each a full gateway round trip, buying something you could have handed over in one sentence.

Today builds that sentence: @ references. Write explain what is wrong with divide in @src/calc.js and the program puts that file's content into the context before sending the request. In the lab, that sentence produces a conclusion with zero tool calls — the same question took three or four turns in week one.

The saving is more than latency. Every tool round trip resends the whole message array, so skipping two turns compounds.

But it has a cost, and that cost is the whole second half of today: you decided what it looks at. Decide wrongly and it answers confidently from irrelevant material; make the material too large and it spends the budget on noise; let the material be quietly truncated and it cannot tell. So today's real discipline is not the syntax but this: every injection must be accounted for.

Sign in and link WeChat to read

Sign in, then link your WeChat mini program account on the account page. Linked accounts share one free article per day. Unlock additional articles with rewarded videos in the mini program.

Mini program QR code

Scan in WeChat to open Dayward AI. Open the same course and chapter, choose the rewarded video, then refresh this page after completion.

Interview questions

  • Implementing file-reference injection (an @ syntax, say), how would you handle directories, binary files, and very large files?实现文件引用注入(比如 @ 语法),你会怎么处理目录、二进制文件和超大文件?
    Common in ChinaCommon overseasBasic#context-injection#file-handling

    🔒 Unlock this chapter to see the answer keys.

  • When injected context exceeds its budget, how do you trim it, and should the trimming rules be visible to the user?注入的上下文超过预算怎么裁?裁剪规则要不要让用户可见?
    Common in ChinaCommon overseasIntermediate#context-budget#trimming

    🔒 Unlock this chapter to see the answer keys.

  • When should you push content into the context yourself, and when should you let the model fetch it with tools?什么时候该主动把内容塞进上下文,什么时候该让模型自己调工具去取?
    Common in ChinaCommon overseasDeep dive#context-strategy#retrieval

    🔒 Unlock this chapter to see the answer keys.

Comments