> For the complete documentation index, see [llms.txt](https://robodex.gitbook.io/robodex-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://robodex.gitbook.io/robodex-docs/architecture/extension-points.md).

# Extension Points

## Add a backend-selectable loop

Add the loop under:

```
packages/research/agent_loops/
```

Then register it through `packages/research/agent_loops/registry.py`.

Required behavior:

* implement the `AgentLoopRunner` protocol,
* return `AgentLoopResult(state=..., hitl=...)`,
* preserve the backend-facing HITL shape,
* add tests in `tests/test_agent_loop_registry.py` or a focused loop test.

Only change `apps/api/routes/designs.py` if the product request or response contract must change.

## Add an experiment-only generation method

Use:

```
packages/research/strategy/
```

Implement `GenerationStrategy.generate(prompt, config) -> list[RobotDesignIR]` and register it with the strategy registry.

Do not make product routes import the strategy directly. If the method should be app-selectable, wrap the needed behavior in an app-compatible agent loop.

## Add a prompt template

Use:

```
packages/research/prompts/templates/
```

Prompt templates are loaded, rendered, versioned, and hashed by `PromptRegistry`. If a prompt affects reproducibility, include it in the reproducibility envelope or run metadata.

## Add a robot representation field

Changes to canonical robot fields usually belong in:

```
packages/pipeline/ir/design_ir.py
packages/pipeline/robot_program.py
apps/web/lib/types.ts
```

Also check:

* product candidate conversion in `apps/api/routes/designs.py`,
* frontend rendering in `apps/web/components/MorphologyViewer.tsx`,
* export conversion in `apps/api/routes/exports.py`,
* tests that assert frontend/backend contract compatibility.

## Add a route

Use `apps/api/routes/` and mount the router in `apps/api/app.py`.

Routes should stay thin. Put reusable workflow logic in a service or SDK module, especially if the frontend and Electron workspace both need it.

## Add export behavior

Start in:

```
apps/api/routes/exports.py
packages/pipeline/compilers/
packages/pipeline/cad/
packages/pipeline/procurement/
```

Export code should accept stored design data or canonical IR. It should not call research loops.

## Add viewer behavior

Start in:

```
apps/web/components/MorphologyViewer.tsx
apps/web/lib/types.ts
```

If the viewer needs a new field, update the backend candidate payload and the frontend contract together.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://robodex.gitbook.io/robodex-docs/architecture/extension-points.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
