Level 2 · Agents & Sub-Agents

Terminal Fundamentals: Controlling Local Agents

Transition from simple prompting to autonomous execution by bridging your AI agent with your local file system and terminal environment.

The Local Harness

Moving from a web interface to a terminal agent changes your relationship with AI. In a chat window, the AI functions like a librarian providing information. In the terminal, the AI becomes a junior engineer with a keyboard. This shift relies on giving the model a harness to read, write, and execute commands directly on your machine. Instead of you copying and pasting code blocks, the agent uses tools to interact with your operating system.

These tools are pre-defined functions that allow the agent to run commands like search, read, and edit. When you ask it to fix a bug, the agent does not just guess the solution. It uses a search tool to find the relevant file, reads the content into its memory, and applies a patch. This creates a real-time feedback loop. The agent can verify its own work by running your local test suite or checking compiler errors, adjusting its approach based on the terminal output it receives.

Connecting Environments via MCP

To move beyond basic file editing, agents use the Model Context Protocol (MCP). Think of MCP as a standardized port that allows the agent to communicate with external services or specialized local software. By configuring MCP servers, you provide the agent with a map of your broader infrastructure. It allows the model to bridge the gap between your local code and the cloud services where that code lives.

For example, an agent equipped with MCP integrations can check GitHub issues, query a database, or interact with deployment platforms. This removes the need for you to act as a middleman. If a deployment fails, the agent can use its MCP connection to pull the logs, identify the failure point, and execute a fix within your local environment. This level of access transforms the agent from a isolated script-writer into an integrated member of your development workflow.

Orchestration and Sub-Agents

Complex projects often exceed the context window, which is the total amount of information an AI can process at one time. To solve this, advanced agents use orchestration. A primary agent acts as a manager, delegating specific portions of a task to sub-agents or separate threads. This allows for modular task management where the main agent maintains the high-level goal while sub-agents focus on granular details like security auditing or unit testing.

Thread delegation keeps the workspace clean. A lead agent might spin up a specialized sub-agent to review your Git history and learn your specific coding patterns. By converting successful multi-step sequences into reusable skills, the agent improves over time. You can eventually trigger these complex workflows with a single command, letting the agent manage the underlying hierarchy of sub-tasks and summaries needed to complete the objective.

Defining the Computing Runway

Autonomous agents require boundaries to prevent them from running in infinite loops or consuming your entire token budget. Managing the computing runway involves setting persistent goals and resource limits. Using specific commands like goal-based triggers allows the agent to keep iterating until a verifiable outcome is achieved. This is a departure from one-off prompts; you are giving the agent a mission and the authority to pursue it until the task is done.

To manage this autonomy safely, you must architect agents with token budgets. This ensures the model stays within a defined cost and time limit. Some systems even allow agents to proactively monitor logs or check site health on a schedule. By providing a persistent identity and a clear runway, you enable the agent to move from reactive assistance to proactive automation, where it manages its own resources to maintain your project's health.

Key takeaways

  • Use terminal-based agents to allow the AI to read, edit, and execute tests directly within your local file system.
  • Implement Model Context Protocol (MCP) to connect your agent to external tools like GitHub, databases, and deployment platforms.
  • Employ thread delegation to split complex tasks among specialized sub-agents, preventing context clutter.
  • Set a computing runway with token budgets to manage costs and prevent agents from stuck loops during autonomous tasks.
  • Convert successful multi-step command sequences into reusable skills to automate recurring engineering workflows.