# Cheat sheet: the agent loop and context

AI Workshop · episode 3: How an agent actually works
https://mihalkevich.com/en/workshop/agent-loop

- [ ] An agent is a model in a loop: reasoning → tool → result → reasoning again
- [ ] Everything the agent «knows» about the project is what's in context: files, command output, CLAUDE.md, your messages
- [ ] Long command output eats context: ask the agent to filter (grep, head), not print everything
- [ ] One session, one task; a new task means a new session or /clear
- [ ] If the agent «forgot» an agreement, it isn't in context — move it into CLAUDE.md
- [ ] Read the log: at which step did the agent decide wrong, and what information was missing

## Harness in this episode

The harness is what surrounds the loop: what the agent sees going in and what checks the result coming out.

## Official documentation

- [How Claude Code works](https://code.claude.com/docs/en/how-claude-code-works)
- [Anthropic — Building effective agents](https://www.anthropic.com/engineering/building-effective-agents)
- [Anthropic — Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents)
- [Claude API — tool use](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview)
- [Anthropic — Writing effective tools for agents](https://www.anthropic.com/engineering/writing-tools-for-agents)

— mihalkevich school
