Skip to content

An open-source, faster Devin alternative

TypeScript

docs: explain how serverless agents work (#662)

Mohamed Habibec9c593c19a3
diff --git a/docs/agents/development.mdx b/docs/agents/development.mdx
deleted file mode 100644
index d2932e54..00000000
--- a/docs/agents/development.mdx
+++ /dev/null
@@ -1,67 +0,0 @@
----
-title: "Cloud development"
-description: "Sync agent code to Development while your application runs locally"
----
-
-OpenComputer's development loop keeps agent execution in the cloud while your
-source files and optional React application stay on your machine.
-
-```bash
-npm run dev
-```
-
-The command performs four jobs:
-
-1. Links the source directory to a cloud project.
-2. Builds and publishes every configured agent to `development`.
-3. Watches `opencomputer/` and publishes changes automatically.
-4. Starts Vite when the project includes the React application.
-
-It also prints the project dashboard URL so you can test the same development
-deployment in the [agent playground](/agents/playground).
-
-## Select a project
-
-On the first run, select an existing project or create one. The choice is saved
-locally and reused by later commands.
-
-```bash
-npx --package @opencomputer/cli opencomputer link
-```
-
-Use an explicit project in scripts or other non-interactive environments:
-
-```bash
-npx --package @opencomputer/cli opencomputer dev --project <project-id-or-slug>
-npx --package @opencomputer/cli opencomputer dev --create-project "Support agents"
-```
-
-## Work with the React application
-
-When a React application is present, the same `npm run dev` process starts both
-cloud synchronization and Vite. Keep it running while using the application;
-the development bridge exists only for the lifetime of that process.
-
-New sessions use the latest synchronized development deployment. Existing
-sessions keep the deployment they started with, so create a new session when
-testing a source change.
-
-## Synchronize development secrets
-
-Put agent credentials in `opencomputer/.env.local`. OpenComputer considers only
-names referenced by `useSecret()` and infers their allowed destinations from
-`defineConnection()` declarations.
-
-```dotenv
-GITHUB_TOKEN=github_pat_...
-```
-
-The CLI asks before the first upload and then watches for changes. Unreferenced
-variables are skipped, and removing a local value does not delete its cloud
-counterpart. See [Secrets and outbound requests](/agents/secrets).
-
-## Development and production stay separate
-
-Saving source advances only `development`. Production remains on its current
-immutable deployment until you explicitly deploy it. See
-[Deployments and environments](/agents/deployments).
diff --git a/docs/agents/examples/feature-flag-hygiene.mdx b/docs/agents/examples/feature-flag-hygiene.mdx
new file mode 100644
index 00000000..1761e9d6
--- /dev/null
+++ b/docs/agents/examples/feature-flag-hygiene.mdx
@@ -0,0 +1,161 @@
+---
+title: "Feature flag hygiene"
+description: "Inspect Unleash flags, find safe cleanup candidates, and open focused pull requests"
+---
+
+The feature flag hygiene example finds old Unleash release flags that remain in
+a repository and prepares one small cleanup pull request per eligible flag. It
+combines an interactive agent, remote MCP servers, code-defined tools, and a
+schedule in one project.
+
+<Card
+ title="OpenComputer × Unleash feature flag hygiene"
+ icon="github"
+ href="https://github.com/diggerhq/opencomputer-example-unleash"
+>
+ Clone the complete agent, schedule, and fixture application from GitHub.
+</Card>
+
+## How it works
+
+```mermaid
+flowchart LR
+ Start[User message or<br/>weekday schedule]
+ Agent[Feature flag<br/>hygiene agent]
+ GitHub[GitHub repository<br/>and ownership]
+ Unleash[Unleash MCP<br/>production state]
+ Check{Safe to remove?}
+ PR[One cleanup PR<br/>per flag]
+ Report[Explain why<br/>the flag was skipped]
+
+ Start --> Agent
+ Agent --> GitHub
+ Agent --> Unleash
+ GitHub --> Check
+ Unleash --> Check
+ Check -->|yes| PR
+ Check -->|no| Report
+```
+
+For each exact feature-flag reference found in executable code, the agent:
+
+1. inspects the flag's production state through the Unleash MCP server;
+2. checks whether it has been live for the configured minimum age;
+3. determines the behavior that should survive removal;
+4. finds an owner through `CODEOWNERS` or recent file history;
+5. runs the narrowest relevant tests;
+6. opens one focused pull request per eligible flag and requests the identified
+ owner as a reviewer.
+
+The agent does not disable, archive, or delete flags in Unleash. Flag retirement
+remains a separate action after the cleanup pull request has been reviewed and
+deployed.
+
+## Select the capabilities
+
+The agent function attaches the model and capabilities needed by the managed
+harness:
+
+```tsx
+export default function Agent() {
+ const input = useInput();
+
+ useModel("anthropic/claude-sonnet-4.6");
+ useMcpServer(unleashMcp);
+ useMcpServer(githubPatMcp);
+
+ useTool(cloneRepository);
+ useTool(findFileOwners);
+ useTool(openCleanupPullRequest);
+
+ // Return the workflow instructions for this render.
+}
+```
+
+The Unleash MCP server supplies feature-flag state. The GitHub MCP server and
+code-defined tools supply repository search, an authenticated source snapshot,
+ownership evidence, branch creation, file updates, pull requests, and reviewer
+selection.
+
+Both credentials are managed by OpenComputer. They are not placed in agent
+source, prompts, commands, tool input, or repository URLs.
+
+## Skip unsafe candidates
+
+The agent refuses to open a pull request when a flag:
+
+- is younger than the minimum-age threshold;
+- is not enabled in production;
+- appears only in documentation;
+- has ambiguous surviving behavior;
+- has failing tests;
+- has no evidence for an owner; or
+- already has an open cleanup branch or pull request.
+
+The screenshot below shows a real interactive run in which all four flags were
+skipped. Three were enabled but too young, while one was not enabled in
+production. The session reports the evidence instead of making a change.
+
+<Frame>
+ <img
+ src="/images/feature-flag-hygiene-session.png"
+ alt="OpenComputer feature flag hygiene session showing four Unleash flags skipped because they were too young or not enabled in production"
+ />
+</Frame>
+
+## Run it on a schedule
+
+The example includes a code-defined weekday schedule:
+
+```ts
+import { defineSchedule } from "@opencomputer/agent";
+
+export default defineSchedule({
+ id: "weekday-hygiene",
+ cron: "0 9 * * 1-5",
+ timezone: "America/Los_Angeles",
+ enabled: ["production"],
+ overlap: "skip",
+ dispatch: {
+ text: "Run the configured feature-flag hygiene review.",
+ payload: {
+ mode: "async",
+ repository: "diggerhq/opencomputer-example-unleash",
+ projectId: "feature-example-test",
+ productionEnvironment: "production",
+ minimumAgeDays: 10,
+ githubAuth: "pat",
+ dryRun: true,
+ },
+ },
+});
+```
+
+Development discovers the schedule but keeps it manual-only by default. Use
+**Run now** to test the exact dispatch safely. Production runs it at 9:00 AM
+Pacific on weekdays and skips an occurrence when an earlier run is still
+active.
+
+The payload's `mode` selects unattended behavior. The transport provenance in
+`input.source` remains available for observability, but it is not used as the
+agent's business-mode switch.
+
+## Try the fixture safely
+
+After cloning the repository and configuring the documented GitHub and Unleash
+development secrets:
+
+```bash
+npm install
+npm run dev
+```
+
+Start with the included fixture and a dry run:
+
+```bash
+npm run session -- "Analyze repository diggerhq/opencomputer-example-unleash using Unleash project feature-example-test and production environment. Use minimumAgeDays 0, GitHub PAT mode, and dryRun true."
+```
+
+The repository README documents the required token permissions, production
+deployment, fixture tests, and the deliberate step from dry-run analysis to
+pull-request creation.
diff --git a/docs/agents/mental-model.mdx b/docs/agents/mental-model.mdx
new file mode 100644
index 00000000..a82a7f10
--- /dev/null
+++ b/docs/agents/mental-model.mdx
@@ -0,0 +1,174 @@
+---
+title: "How it works"
+description: "A mental model for agent functions, the managed harness, durable sessions, capabilities, and triggers"
+---
+
+OpenComputer runs agents defined as TypeScript functions. You describe the
+agent for the current step; OpenComputer supplies the managed harness that
+calls the model, executes tools, streams output, and records the durable
+session.
+
+```mermaid
+flowchart LR
+ Trigger[Message, schedule,<br/>webhook, or channel]
+ Session[Durable session]
+ Harness[Managed harness]
+ Function[Your agent function]
+ Model[Model]
+ Tools[Tools and MCP servers]
+
+ Trigger --> Session
+ Session --> Harness
+ Harness --> Function
+ Function -->|instructions, model,<br/>capabilities| Harness
+ Harness --> Model
+ Model -->|tool request| Harness
+ Harness --> Tools
+ Tools -->|result| Harness
+ Harness -->|events and messages| Session
+```
+
+## The runtime model
+
+### Your agent function describes the next step
+
+The default export is a synchronous function. It reads the current input,
+selects resources with hooks, and returns instructions:
+
+```tsx
+import { useInput, useModel, useTool } from "@opencomputer/agent";
+import { inspectRepository } from "./tools/inspect-repository";
+
+export default function Agent() {
+ const input = useInput();
+
+ useModel("anthropic/claude-sonnet-4.6");
+ useTool(inspectRepository);
+
+ return `
+ You are a release-readiness agent.
+ Inspect the repository before giving a RELEASE or DO NOT RELEASE verdict.
+
+ Current request: ${input.text ?? "Review the configured repository."}
+ `;
+}
+```
+
+The function does not call the model or execute the tool. Each hook contributes
+to the effective configuration for the next model step.
+
+### The harness performs the loop
+
+OpenComputer owns the agent harness. For each step it:
+
+1. renders the agent function;
+2. builds a model request from the returned instructions and selected resources;
+3. streams the model response;
+4. validates and executes requested tools;
+5. records the resulting events; and
+6. renders again when another model step is required.
+
+```mermaid
+sequenceDiagram
+ participant S as Session
+ participant H as Managed harness
+ participant A as Agent function
+ participant M as Model
+ participant T as Tool
+
+ S->>H: Start or resume a turn
+ H->>A: Render current input and state
+ A-->>H: Instructions and capabilities
+ H->>M: Model request
+ M-->>H: Tool request
+ H->>T: Execute
+ T-->>H: Result
+ H->>S: Record events
+ H->>A: Render the next step
+ A-->>H: Updated configuration
+ H->>M: Continue
+ M-->>H: Final response
+ H->>S: Record completion
+```
+
+Because a function can render more than once during a turn, keep it synchronous
+and free of external side effects. Network calls and mutations belong in
+[tools](/agents/tools) or remote [MCP servers](/agents/mcp).
+
+### A session makes execution durable
+
+A [session](/agents/sessions) stores the conversation and runtime events across
+turns. Clients can disconnect, reconnect, and continue without reconstructing
+the agent's history themselves.
+
+Every session remains pinned to the immutable deployment it started with. A
+new development sync or production deployment affects new sessions, not code
+already running inside an existing session.
+
+## Capabilities are selected, not executed, during render
+
+Use the narrowest capability that fits the work:
+
+| Capability | What the harness receives |
+| --- | --- |
+| `useTool(tool)` | One typed operation implemented by your project |
+| `useMcpServer(server)` | A collection of tools advertised by a remote MCP server |
+| `useSubagent(agent)` | Another project agent available for delegation |
+| A skill under `skills/` | Reusable instructions and supporting resources |
+
+The model decides whether to request an available tool. The harness remains
+responsible for validating the request, executing it, and recording the
+result. See [Agent capabilities](/agents/capabilities) for the full comparison.
+
+## Deployment registers; rendering selects
+
+A deployment packages the agents and resources that are allowed to exist. A
+render selects which of those resources are available for one model step.
+
+```mermaid
+flowchart LR
+ Source[Project source]
+ Deployment[Immutable deployment]
+ Session[Session pinned<br/>to deployment]
+ Render[Agent render]
+ Step[Instructions, model,<br/>selected capabilities]
+
+ Source --> Deployment
+ Deployment --> Session
+ Session --> Render
+ Render --> Step
+```
+
+Development and Production point to different deployments and keep operational
+configuration—such as secrets, schedule state, webhook tokens, and channel
+bindings—separate. Read
+[Deployments and environments](/agents/deployments) for that lifecycle.
+
+## Remember this
+
+> **The agent function decides what the agent is for this step.**
+> **The harness decides how to run that step.**
+> **The session remembers what happened.**
+
+## Explore each concept
+
+<CardGroup cols={2}>
+ <Card title="Reactive agents" icon="code" href="/agents/reactive-agents">
+ Define instructions and select resources with ordinary TypeScript.
+ </Card>
+ <Card title="Sessions and turns" icon="comments" href="/agents/sessions">
+ Understand durable conversations and runtime events.
+ </Card>
+ <Card title="Capabilities" icon="shapes" href="/agents/capabilities">
+ Choose between tools, MCP servers, skills, and subagents.
+ </Card>
+ <Card title="Schedules" icon="clock" href="/agents/schedules">
+ Start recurring sessions from code-defined cron schedules.
+ </Card>
+ <Card title="Webhooks" icon="webhook" href="/agents/webhooks">
+ Start sessions from authenticated external services.
+ </Card>
+ <Card title="Channels and outboxes" icon="message" href="/agents/channels">
+ Receive conversational events and publish durable notifications.
+ </Card>
+</CardGroup>
diff --git a/docs/agents/overview.mdx b/docs/agents/overview.mdx
index 78a2c469..51b91fbc 100644
--- a/docs/agents/overview.mdx
+++ b/docs/agents/overview.mdx
@@ -33,8 +33,8 @@ subagents needed for that render.
<Card title="Reactive agents" icon="code" href="/agents/reactive-agents">
Build agent behavior with a function and conditional hooks.
</Card>
- <Card title="Cloud development" icon="cloud" href="/agents/development">
- Sync source directly to a managed development environment.
+ <Card title="Deployments" icon="cloud" href="/agents/deployments">
+ Move immutable agent versions through Development and Production.
</Card>
<Card title="Sessions" icon="comments" href="/agents/sessions">
Stream responses and inspect durable conversations.
diff --git a/docs/agents/quickstart.mdx b/docs/agents/quickstart.mdx
index a6e8bc95..0b7184ee 100644
--- a/docs/agents/quickstart.mdx
+++ b/docs/agents/quickstart.mdx
@@ -63,8 +63,9 @@ Saving the file publishes a new development deployment. Start a new playground
or client session to test it; an existing session keeps the deployment it
started with.
-See [Cloud development](/agents/development) for project selection, automatic
-secret synchronization, and the full development lifecycle.
+See [Projects](/agents/projects) for project selection and
+[Secrets and runtime variables](/agents/secrets) for automatic development
+secret synchronization.
## 5. Deploy to production
diff --git a/docs/docs.json b/docs/docs.json
index 6640c51a..a6402841 100644
--- a/docs/docs.json
+++ b/docs/docs.json
@@ -30,10 +30,9 @@
"group": "Getting started",
"pages": [
"agents/overview",
+ "agents/mental-model",
"agents/quickstart",
- "agents/projects",
- "agents/development",
- "agents/deployments"
+ "agents/projects"
]
},
{
@@ -46,7 +45,8 @@
"agents/capabilities",
"agents/channels",
"agents/outboxes",
- "agents/secrets"
+ "agents/secrets",
+ "agents/deployments"
]
},
{
@@ -69,7 +69,10 @@
},
{
"group": "Examples",
- "pages": ["agents/examples/gtm-engineer"]
+ "pages": [
+ "agents/examples/gtm-engineer",
+ "agents/examples/feature-flag-hygiene"
+ ]
}
]
},
diff --git a/docs/images/feature-flag-hygiene-session.png b/docs/images/feature-flag-hygiene-session.png
new file mode 100644
index 00000000..fea1c550
Binary files /dev/null and b/docs/images/feature-flag-hygiene-session.png differ