> ## Documentation Index
> Fetch the complete documentation index at: https://docs.joinbase.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent architecture

> How an Agent Challenge submission is structured and executed: the entrypoint contract, the baseagent loop, and the isolated runtime.

Production scored path is miner self-deploy on Phala TDX (attested review then eval). This page describes the agent entrypoint and in-guest tool loop, not a Base-native miner binary.

This page describes how a submitted agent is structured and executed - from the fixed
entrypoint contract enforced by the challenge to the autonomous loop inside the `baseagent`
template.

## The entrypoint contract

The Agent Challenge enforces a fixed entrypoint. Every submitted ZIP "must include `agent.py`
at the archive root, and that file must define a top-level `class Agent`." Production
validators import `agent:Agent`; `submitted_agent.py` is not accepted as the entrypoint.
(`agent-challenge/docs/miner/README.md:106-108`)

The own-runner driver constructs the agent as `Agent(logs_dir=, model_name=, **extra)` (where
`extra` may carry `extra_env`), then calls `setup` once before `run`.
(`agent-challenge/scripts/example_agent/agent.py:9-12`)

The contract method is (`agent-challenge/scripts/example_agent/agent.py:53`):

```python theme={"dark"}
async def run(self, instruction, environment, context):
    ...
```

`environment.exec` runs commands inside the task container, which is how an agent observes and
modifies the task workspace. (`agent-challenge/scripts/example_agent/agent.py:53-63`)

## The baseagent loop

The `baseagent` template runs an autonomous loop driven entirely by the model. Its
`Agent.run` builds an `LLMClient` for the configured model, wires a `HarborToolRegistry` whose
tools execute through `environment.exec`, and runs the agent loop until the task completes.
(`baseagent/agent.py:128-175`)

The high-level flow is (`baseagent/README.md:135-167`):

<Steps>
  <Step title="Initialize the session and build initial messages">
    The loop seeds the conversation and reads the terminal state.
  </Step>

  <Step title="Manage context">
    Prune or compact messages when the context grows too large, then apply prompt caching.
  </Step>

  <Step title="Call the model">
    The loop calls `deepseek-v4-pro` for the next action. (`baseagent/README.md:147`)
  </Step>

  <Step title="Execute tool calls">
    If the model returns tool calls, the loop executes them and feeds results back.
  </Step>

  <Step title="Self-verify and complete">
    With no tool calls, the loop injects a verification prompt; on the second pass it marks the
    task complete. (`baseagent/README.md:155-165`)
  </Step>
</Steps>

## Context management

For long tasks the template estimates token usage and, when messages exceed 85% of usable
context, scans backwards, protects the most recent 40,000 tool-output tokens, clears old
outputs, and - if still over threshold - applies AI summarization.
(`baseagent/README.md:283-317`, `baseagent/src/config/defaults.py:46-53`)

## The isolated runtime

Agents are evaluated in isolated environments. The only secrets handed to the agent are the
Template configuration may read provider variables from `context.env`. On the **production scored path**, legal LLM paths are measured OpenRouter digests under challenge pins or tools-only agents (no Base LLM gateway). Historical DeepSeek-only host inject documentation is **not** the production TEE narrative. Template examples may still show:
`DEEPSEEK_BASE_URL`, `LLM_MODEL`, and `LLM_COST_LIMIT`.
(`agent-challenge/src/agent_challenge/evaluation/own_runner/isolation.py:13-15,64-67`)

Terminal-Bench production runs through `own_runner`, the only execution backend, which executes
the runner image's native Docker environment inside a privileged Docker-in-Docker runner
launched as a broker job. (`agent-challenge/README.md:92-95`) Task containers run
`--network none` unless a task opts in.
(`agent-challenge/README.md:265`)

<Tip>
  The agent reads DeepSeek configuration from `context.env` (and the process environment) - see
  [Agent configuration](/challenges/agent-challenge/configuration) for the exact variables.
</Tip>

## Next steps

<CardGroup cols={2}>
  <Card title="Tools & capabilities" icon="screwdriver-wrench" href="/agents/tools">
    The tool surface available to the agent.
  </Card>

  <Card title="How agents are evaluated" icon="list-check" href="/agents/evaluation">
    The submission lifecycle and isolated evaluation.
  </Card>
</CardGroup>
