Live data from Hacker News

Building a coding agent in Swift from scratch

github.com

11–20 of 30 posts

Re: Building a coding agent in Swift from scratch

#11
post #9

the interesting design tension i ran into building in this space is context management for longer sessions. the model accumulates tool call history that degrades output quality well before you hit the hard context limit - you start seeing "let me check that again" loops and increasingly hedged tool selection.a few things that helped: (1) summarizing completed sub-task outputs into a compact working-memory block that…

Yeah, this is basically what I ran into too. I actually wrote about this in Stage 6 (https://ivanmagda.dev/posts/s06-context-compaction/) I went with your option (1): once history crosses a token threshold, the agent asks the model to summarize everything so far, then swaps the full history for that summary. Keeps the context window clean, though you do lose the ability to go back and reference exact earlier tool outputs.

The hard part was picking when to trigger it. Too early and you're throwing away useful context. Too late and the model's already struggling. I ended up just using a simple token count — nothing clever, but it works.

And yeah, the Swift angle was genuinely fun. Defining tool schemas as Codable structs that auto-generate JSON schemas at compile time, getting compiler errors instead of runtime API failures is a huge win.

Re: Building a coding agent in Swift from scratch

#12

I think this is a good learning project, based in a long perusal of the github repo. One suggestion: don’t call the CLI component of the project ‘claude’ - that seems like asking for legal takedown problems.

Good point, I'll rename the binary. Thanks for actually going through the repo.

Re: Building a coding agent in Swift from scratch

#17

[flagged]

I wouldn't say most of the magic is there, but I do think a lot of the progress we've seen in the last few years has been external to the models, and people sometimes miss that. For example, Claude Code has improved by leaps and bounds because the tooling has improved so much, from what I can see. But the underlying model is still what makes this relatively simple tooling so useful.

Re: Building a coding agent in Swift from scratch

#18

[flagged]

I wouldn't say most of the magic is there, but I do think a lot of the progress we've seen in the last few years has been external to the models, and people sometimes miss that. For example, Claude Code has improved by leaps and bounds because the tooling has improved so much, from what I can see. But the underlying model is still what makes this relatively simple tooling so useful.

Agreed. That's the core hypothesis behind this learning project — model is the magic, and the agent loop is just a thin, transparent wrapper around it. The goal of building it stage-by-stage was to prove you don't need a massive, complex framework to get good agentic behavior.

Re: Building a coding agent in Swift from scratch

#20
post #7

Interesting, I'm also building one in Swift :D Seems like a good learning experience.

I’m also working on agents in Swift with the AFM, just having it locally already installed is a huge selling point. I think narrowly-focused agents with good tooling and architecture could accomplish quite a bit, with tradeoffs in speed and cost. But I’m under the assumption that local models (like frontier models) will only get better with time
Post reply on HN