@penguinharness/agent-development 0.2.11 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +21 -3
- package/skills/agent-initialization/SKILL.md +182 -0
- package/skills/agent-initialization/reference/hooks.md +112 -0
- package/skills/penguin-config/SKILL.md +28 -8
- package/skills/penguin-orchestration/SKILL.md +31 -27
- package/skills/penguin-plugin/SKILL.md +137 -0
- package/skills/penguin-sdk/SKILL.md +94 -20
- package/skills/penguin-sdk/reference/agent-api.md +159 -0
- package/skills/unified-llm-api/SKILL.md +132 -80
- package/plugin.json +0 -8
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: penguin-plugin
|
|
3
|
+
description: Use for workflows — the tabs and pages beside the chat, with server code behind them, that an Agent keeps in its own `workflows/` folder inside PenguinHarness — building one, changing it, showing it as the whole app, restoring an earlier version, and removing a tab or a whole workflow when the user wants the custom UI gone.
|
|
4
|
+
version: 2026.10.12.2
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Penguin plugins: workflows
|
|
8
|
+
|
|
9
|
+
Inside PenguinHarness an Agent can hold *workflows*: small plugin packages in its own directory, written in TypeScript, that the server boots as module trees, shows as tabs beside the chat, reloads on every file change, and versions so any edit can be undone. This is the same module mechanism the server itself is built from — manifests as data, everything checked before any code runs — so a workflow that does not type-check, that was written against an interface version this server no longer fits, or whose manifests do not hold together fails to load with the problem named, while the previous version keeps serving.
|
|
10
|
+
|
|
11
|
+
A workflow is a plugin of the server's own kind, which is where this skill's name comes from. It is not a program that reaches an agent from outside, so it takes neither of the penguin-sdk skill's two ways, and that skill's question does not apply to it.
|
|
12
|
+
|
|
13
|
+
## Before you start
|
|
14
|
+
|
|
15
|
+
If the user's message only invokes this skill (e.g. "use penguin-plugin skill") without saying what the workflow is for, ask the user what they want it to do. Once the request is concrete, do **not** ask follow-up questions: build it end to end and list the assumptions you made in your final reply. A request to undo, revert or remove the UI is the exception: work out which of the four in *Undoing, reverting, removing* is meant first.
|
|
16
|
+
|
|
17
|
+
## Start here — the whole loop is files
|
|
18
|
+
|
|
19
|
+
You need nothing but your file tools: no HTTP API, no port, no login, no server source. Do not go looking for the running server, its bundle or a checkout of the repository, and do not probe its API — everything you need to know is written into the workflow folder by the server itself.
|
|
20
|
+
|
|
21
|
+
1. *Where:* your Agent directory is `<App Data Dir>/agents/<Agent ID>/` — both values are in the Environment section of your system prompt. Workflows live in its `workflows/` folder (create it if it is missing); `ls` it to see what already exists before you add or change anything.
|
|
22
|
+
2. *Scaffold:* write the three files below — `package.json`, a minimal `index.ts`, one page under `ui/`. The server notices the folder within a second or two.
|
|
23
|
+
3. *Read what the server wrote back:* `.build/status.json` is the result of the last load — `{ ok, revision, checkedAt, error, tabs, hints }`. `ok: false` carries the compiler's or the checker's message with file, line and reason; fix that and look again. `ok: true` with an empty `tabs` means NOTHING shows in the user's chat page, however finished the page under `ui/` is: a page is only a file until `package.json` contributes a tab for it (see *Tabs are contributions* below), and `hints` spells out the entry to add. `.harness/README.md` is this same contract in the harness's own words — trust it over this skill if the two ever differ. `.harness/plugin.d.ts` is the exact `WorkflowHost` and `WorkflowMain` THIS harness offers — read it once instead of guessing at an interface.
|
|
24
|
+
4. *Iterate:* edit, wait a moment, read `.build/status.json` again. `checkedAt` changing tells you the server saw your edit. When it says `ok: true`, lists your tab under `tabs` and has no `hints`, the tab is already in the user's chat page — and not before. If `status.json` never appears, ask the user to open this Agent's chat page once (that is what starts the server watching the folder) rather than hunting for another way in.
|
|
25
|
+
|
|
26
|
+
What you do not need to find out by experiment: `host.run` resolves as soon as the turn has STARTED (not when it ends) with `{ sessionId, queued }`; `host.sessionStatus(id)` returns `"idle"`, `"running"` or `"compacting"`, so a run is finished when its Session is back to `"idle"`; `host.getState()` is synchronous and returns whatever was last passed to `setState` (`null` before the first one).
|
|
27
|
+
|
|
28
|
+
## Layout
|
|
29
|
+
|
|
30
|
+
Layout, under `<root>/<project_id>/agents/<agent_id>/workflows/<workflow_id>/` (beside `agent_state/`):
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
package.json "type": "module" and "penguin": { "modules": [ …manifests ] } — no dependency to install
|
|
34
|
+
index.ts default export { modules: { <Name>: { create(ctx) } } } satisfies WorkflowPackage — TypeScript only
|
|
35
|
+
ui/ the workflow's pages and their assets; which of them are tabs is what the manifest contributes
|
|
36
|
+
state.json the workflow's own document, kept by the server across reloads and rollbacks
|
|
37
|
+
.harness/ the server's: the types this workflow was written against (plugin.d.ts) and their interface table — read plugin.d.ts, never edit it
|
|
38
|
+
.build/ the server's: emitted JavaScript per revision, and status.json — the result of the last load; read it, never edit it
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## The manifest and the handler
|
|
42
|
+
|
|
43
|
+
The root manifest is named `Workflow`; it requires the host, provides the handler, and contributes its tabs:
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"name": "demo",
|
|
48
|
+
"version": "0.1.0",
|
|
49
|
+
"type": "module",
|
|
50
|
+
"penguin": {
|
|
51
|
+
"modules": [
|
|
52
|
+
{
|
|
53
|
+
"name": "Workflow",
|
|
54
|
+
"requires": { "host": { "iface": "@prismshadow/penguin-server#WorkflowHost", "from": "Host" } },
|
|
55
|
+
"provides": { "main": "@prismshadow/penguin-server#WorkflowMain" },
|
|
56
|
+
"contributes": {
|
|
57
|
+
"WebModule.sessionTabs": [
|
|
58
|
+
{ "id": "demo.main", "key": "main", "title": "Demo", "titleZh": "演示", "renderer": { "iframe": { "src": "ui/index.html" } } }
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import type { WorkflowPackage } from "@prismshadow/penguin-server/plugin";
|
|
69
|
+
|
|
70
|
+
export default {
|
|
71
|
+
modules: {
|
|
72
|
+
Workflow: {
|
|
73
|
+
create({ use }) {
|
|
74
|
+
const host = use.host;
|
|
75
|
+
return {
|
|
76
|
+
api: {
|
|
77
|
+
main: {
|
|
78
|
+
async handle(req) {
|
|
79
|
+
// req = { method, path, query, body }; path is below the workflow's api/ mount
|
|
80
|
+
if (req.path === "/ask" && req.method === "POST") {
|
|
81
|
+
const { question } = req.body as { question: string };
|
|
82
|
+
// The SDK's two verbs: open a Session, run a turn in it.
|
|
83
|
+
const { sessionId } = await host.createSession();
|
|
84
|
+
await host.run(sessionId, [{ text: question }]);
|
|
85
|
+
return { body: { sessionId } };
|
|
86
|
+
}
|
|
87
|
+
return { status: 404, body: { error: "no such route" } };
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
} satisfies WorkflowPackage;
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## TypeScript, checked by the server
|
|
99
|
+
|
|
100
|
+
There is no build step to run, no `tsconfig.json` to write and nothing to `npm install`: the server builds one program from `index.ts` (and the `.ts` files it imports, with `.js` in the import specifier as NodeNext asks) under options it fixes itself — `strict` among them — refuses the load on any diagnostic, reporting file, line and reason, and otherwise emits into `.build/<revision>/` and imports that. `satisfies WorkflowPackage` is what types `use.host` and `req`; without it `strict` refuses the untyped parameters. A folder holding `index.js` or `index.mjs` instead is refused outright.
|
|
101
|
+
|
|
102
|
+
## Types come from the harness that runs you
|
|
103
|
+
|
|
104
|
+
One machine can run several harnesses — a release, a checkout, a platform someone pushed with interfaces of its own — and none of them is a version on npm, so `@prismshadow/penguin-server/plugin` is not a package here: the first time the server loads the folder it writes `.harness/plugin.d.ts`, rendered from ITS OWN interface table, and that is what the import resolves to. Create `package.json` and a minimal `index.ts`, let the server load it once, then read `.harness/plugin.d.ts` for the exact `WorkflowHost` this harness offers. The server then leaves `.harness/` alone: it is the record of what the workflow was written against, and a later generation of the platform is COMPARED with it, by the TypeScript compiler, both for what the workflow requires and what it provides — a host method you rely on that has since gone is a load error naming it, not a failure on the first call. To move a workflow onto the harness that runs it now, delete `.harness/` and fix what the compiler then reports.
|
|
105
|
+
|
|
106
|
+
## Tabs are contributions
|
|
107
|
+
|
|
108
|
+
Each entry under `WebModule.sessionTabs` is one tab beside the chat: `key` (unique in the workflow, part of the full-page URL), `title` / `titleZh`, and a `renderer` whose `iframe.src` is a file under `ui/`. Several entries make several tabs; none makes a server-only workflow. It is the same slot, written the same way, a plugin contributes to — the host opens it to workflows and scopes the tab to this Agent. A slot the host has not opened (`WebModule.pages`, say) is refused by name.
|
|
109
|
+
|
|
110
|
+
## The host
|
|
111
|
+
|
|
112
|
+
`WorkflowHost` (published as module `Host`) speaks the SDK's verbs, scoped to the workflow's Project: `listAgents()` returns the Project's Agents as `{ agentId }[]`; `createSession({ agentId? })` opens a Session of this Agent — or of another Agent of the same Project — and returns `{ sessionId }`; `run(sessionId, [{ text: "…" }])` — the SDK's `session.run`, its input items spelled out because a workflow has no package to import `userText` from — runs one turn in a Session, new or existing, and returns `{ sessionId, queued }` once it has started (a busy Session queues it as a follow-up; the Agent hears it as a message from the server, not from a person); `sessionStatus(sessionId)` says `idle` / `running` / …; `getState()` / `setState(doc)` over `state.json` (`getState()` is `unknown`: narrow it); `log(text)`. More modules may be listed in `penguin.modules` and named as `children` of `Workflow`, with their own `requires` between them — the tree is checked as a whole.
|
|
113
|
+
|
|
114
|
+
## HTTP
|
|
115
|
+
|
|
116
|
+
HTTP, all under `/api/projects/:projectId/agents/:agentId/workflows` (Project members only): `GET /` lists the workflows with their `revision`, `uiRev`, `tabs` (each page's URL resolved) and current load `error`; `GET /:id/ui/*` serves a file of `ui/` (there is no default document — a tab names its page); any method on `/:id/api/*` reaches `handle` — JSON by default in both directions (`req.body` parsed, `{ status?, body? }` answered as JSON), and anything else when you say so: a non-JSON request body arrives as `req.bytes` (a `Uint8Array`; `req.headers` has its `content-type`, never the app's cookie), and a response that names a `content-type` in `headers` sends `body` as the string you wrote, or `bytes` for binary, or `stream` — an async iterable (an `async function*`) of strings or `Uint8Array`s, each chunk written to the client as you yield it, which is how server-sent events and a model's token-by-token answer get through without waiting for the end (relay an upstream stream by yielding its chunks; a `finally` in the generator runs when the client goes away — though a generator parked inside an `await` only gets there once that await settles, so give a relay its own timeout rather than trusting the disconnect) — with `location` + a 3xx status for a redirect. That is how a handler serves a page it renders, an upload, a download, or the pages of a program it runs on this machine: fetch `http://127.0.0.1:<port>/…` from the HANDLER and return what came back — never put `127.0.0.1` in a page, because the page runs in the user's browser, which may be on another machine than you are; `POST /:id/reload`; `GET /:id/history` lists recorded versions; `POST /:id/rollback { revision }` restores one (code only — `state.json` stays) and reloads. `DELETE /:id` removes the workflow together with its recorded versions. From a page directly under `ui/`, call your handler with a relative `fetch("../api/…")`; the Web App shows each page in its tab and reloads it when `uiRev` changes.
|
|
117
|
+
|
|
118
|
+
## Undoing, reverting, removing (撤销 / 还原 / 清掉界面)
|
|
119
|
+
|
|
120
|
+
When the user asks to undo the UI, revert it, clean it up or get the chat page back the way it was, they are asking you to TAKE SOMETHING AWAY — never to build something. Do not answer such a request by adding a feature (a reset button, an undo stack, a new route). Work out which of the four below they mean; if it is not obvious from what they said, ask in one line before touching anything. Everything about a workflow is files in your own Agent directory, so each of these is a file operation you make yourself — list `workflows/` first to see what exists. The server notices within a moment and the user's tabs follow without a refresh.
|
|
121
|
+
|
|
122
|
+
1. *"Get rid of it" / "back to before there was any custom UI" / 回到没定义 UI 的状态* — remove the workflow entirely: delete the folder `workflows/<id>/` **and** its recorded versions `workflows-history/<id>/`. That is everything there is; the tabs disappear and nothing else of the Agent is touched. It cannot be undone, so say so in one line first, and never delete a workflow you were not asked to remove. (The user can do the same from the tab's bar: *Remove*, two clicks.)
|
|
123
|
+
2. *"Undo your last change" / "it was better before"* — go back to an earlier version of the CODE: the recorded versions are full copies under `workflows-history/<id>/<revision>/` (`versions.json` lists them, newest first); copy that version's files over the folder and the server reloads it. The tab's bar offers the same as *History → Restore*.
|
|
124
|
+
3. *"Remove that tab" / "I only want the first page"* — delete its entry under `WebModule.sessionTabs` in `package.json` (and its page under `ui/` if nothing else uses it). With `"contributes": {}` the workflow keeps its server code and has no UI at all.
|
|
125
|
+
4. *"Bring back the data"* — you cannot: `state.json` is never part of a version (restoring code leaves the data as it is) and it has no history of its own. Say so plainly rather than inventing a recovery.
|
|
126
|
+
|
|
127
|
+
One constraint follows from 4, and it is a constraint on you, not a task to go and do: the workflow's data is only ever changed through `host.setState` from its handler. Never edit or delete `state.json` by hand — not to reset a board, not to fix a record — because what you overwrite is gone for good.
|
|
128
|
+
|
|
129
|
+
Your handler's responses are served from the app's own origin, so anything you echo back from a request is executed there: escape what you put into HTML, and treat a value that came in over `/api/*` as untrusted even though only Project members can reach it.
|
|
130
|
+
|
|
131
|
+
## Theme
|
|
132
|
+
|
|
133
|
+
A workflow page is a separate document, so it inherits nothing from the app's stylesheet by itself. The Web App stamps `light`/`dark` on the page's root, copies its resolved palette (the gray scale, the accent pair, the font stack, the root font size) onto it, and injects `/workflow-ui.css` first in the head — a base stylesheet that styles plain HTML (headings, lists, forms, tables, code) to match the app and exposes `--wf-bg`, `--wf-fg`, `--wf-muted`, `--wf-border`, `--wf-surface`, `--wf-accent`, `--wf-accent-fg`, plus the classes `wf-primary` (a button), `wf-card`, `wf-rows`, `wf-row`, `wf-muted`. Write plain markup, take every colour and font from those variables, and the page follows the user through a theme or accent change; hardcode them and it clashes in one theme or the other. The page's own rules always win, and linking `/workflow-ui.css` yourself makes it look right when opened outside the app too.
|
|
134
|
+
|
|
135
|
+
## Filling the app
|
|
136
|
+
|
|
137
|
+
A page can be shown as the whole app — no sidebar, no chat, no tab strip — at `/app/<project>/<agent>/<workflow>[/<tab key>]` (the workflow's first tab when no key is given): the tab's *Fill the app* button goes there, `penguin web --app <project>/<agent>/<workflow>[/<tab key>]` opens the browser straight onto it, and the page itself can ask with `parent.postMessage({ type: "penguin:fill-app" }, "*")`. The way back is the command palette, whose *Exit full page* lands on that Agent's chat. Its chord is Ctrl+Alt+P (⌥⌘P on macOS) unless the user rebound it under Settings › Keyboard shortcuts. A key pressed inside the page reaches the app only when the page has not handled it, so a page must never `preventDefault` that chord: on this route it is the only way out.
|
|
@@ -1,23 +1,88 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: penguin-sdk
|
|
3
|
-
description: Use whenever the user wants to build an agent application — their own program with an
|
|
3
|
+
description: Use whenever the user wants to build an agent application — their own program with an agent in it, such as an AI app, an agentic app, a RAG app or a bot — or to connect a program to a Penguin agent. A program reaches an agent in one of two ways, and the skill asks the user which before building — embedded with the Penguin Harness SDK (`@prismshadow/penguin-core`, no server), or over the Penguin server's Agent API (AMSP, with the `@prismshadow/amsp` client or curl). This is writing application code, not configuring an Agent State inside PenguinHarness. Covers self-contained projects, the createSession/run streaming loop with thinking and image messages, wiring the user's existing tools in as CLI commands, a complete RAG recipe that ingests documents into a knowledge base and answers with citations behind a web UI, and the Agent API client. Workflows — the tabs and pages beside the chat that an Agent keeps for itself inside PenguinHarness — are the penguin-plugin skill's.
|
|
4
|
+
version: 2026.10.12.2
|
|
4
5
|
---
|
|
5
6
|
|
|
6
|
-
# Penguin Harness SDK
|
|
7
|
+
# Penguin Harness SDK and Agent API
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
This skill builds programs that use a Penguin agent. A program reaches one in either of two ways, embedded with the SDK or through the Penguin server's Agent API, and the user picks which. Workflows — pages and server code an Agent keeps inside PenguinHarness — are a third thing, and the penguin-plugin skill's.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
To have an agent perform a task for you, use the `run_subagent` tool: both ways are for programs, not for handing off your own work.
|
|
12
|
+
|
|
13
|
+
## Two ways to reach an agent
|
|
14
|
+
|
|
15
|
+
**The SDK: `@prismshadow/penguin-core`, embedded in the program.**
|
|
16
|
+
|
|
17
|
+
- *What it is.* The agent loop as a TypeScript library. The program creates its own Agent from a data directory inside the project and runs its Sessions in-process. No Penguin server is involved, at build time or at run time.
|
|
18
|
+
- *What you get.* The basic agent loop: the Agent State files (`AGENTS.md`, Skills, tools), the streamed OmniMessages and an `approve` callback for every tool call, in a self-contained folder that runs wherever Node 24 does, on the program's own model key.
|
|
19
|
+
- *What you don't get.* No server-managed Sessions (the program keeps its own), no visibility in the Web App, no approvals UI (the program answers in code) and no cost center. The embedded agent belongs to the program: changes to an Agent inside PenguinHarness never reach it.
|
|
20
|
+
- *Choose it when* the program must stand alone: shipped to other machines or people, run where no Penguin server is, or with the agent built into the product.
|
|
21
|
+
|
|
22
|
+
**The API: Penguin's Agent API, over AMSP.**
|
|
23
|
+
|
|
24
|
+
- *What it is.* The program calls an Agent that lives in PenguinHarness, over HTTP. The Penguin server runs each turn and streams it back as AMSP events, and the program continues a conversation by its Session id. TypeScript uses the `@prismshadow/amsp` client (`AgentClient`); any other language, or curl, speaks HTTP and SSE directly.
|
|
25
|
+
- *What you get.* The Agent as PenguinHarness runs it: its `AGENTS.md`, Skills and memory, on the Project's models and credentials, so the program holds no model key. The server keeps the conversations as archived chats (**Settings › Archived chats** in the Web App), where a person finds one and unarchives it to read it and answer its approvals, and their usage lands in the cost center.
|
|
26
|
+
- *What it requires.* A running Penguin server that the program can reach over the network; API access turned on for that Agent by the Project's owner, on the Agent's **API** tab; and a key created there, shown once. You never turn these on yourself (see *The API path*).
|
|
27
|
+
- *Choose it when* the Agent already exists in PenguinHarness or should be managed there, people need to see its conversations or costs, or the program is not written in TypeScript.
|
|
28
|
+
|
|
29
|
+
### Ask which way first
|
|
30
|
+
|
|
31
|
+
Whenever the user asks to connect a program to an agent, or to build a program with an agent in it (an AI, agentic or RAG app, a bot, a service, a script), ask which way before you write anything, even when the request is otherwise concrete. It is the only question a concrete request gets: it overrides the no-follow-up-questions default of *Before you start* for this one question.
|
|
32
|
+
|
|
33
|
+
Do not ask when the way is already chosen:
|
|
34
|
+
|
|
35
|
+
- in the user's message: "use the SDK", "standalone", "without the Penguin server" or "embed the agent" chooses the SDK; "call it over the API", "through the Agent API", "with AMSP", "with `@prismshadow/amsp`" or "with curl" chooses the API;
|
|
36
|
+
- earlier in this conversation, for the same program.
|
|
37
|
+
|
|
38
|
+
Naming this skill does not choose a way. Workflows (the penguin-plugin skill) take neither way and need no question; neither does connecting a Feishu, Telegram, QQ or WeChat bot to a conversation, which is the Web App's Remote control.
|
|
39
|
+
|
|
40
|
+
Ask with one sentence and this choice block, in the user's language, as the end of your reply. Mark one option `"recommended": true` only when the request leans that way: an Agent the user already has in PenguinHarness leans to the API, an app to ship to others leans to the SDK.
|
|
41
|
+
|
|
42
|
+
````markdown
|
|
43
|
+
Your program can reach the agent in two ways: embedded with the SDK, or through the Penguin server's Agent API.
|
|
13
44
|
|
|
14
|
-
|
|
45
|
+
```a2ui
|
|
46
|
+
{
|
|
47
|
+
"type": "choice",
|
|
48
|
+
"id": "agent-access",
|
|
49
|
+
"question": "How should the program reach the agent?",
|
|
50
|
+
"options": [
|
|
51
|
+
{
|
|
52
|
+
"label": "SDK: embed the agent",
|
|
53
|
+
"value": "Use the SDK: embed the agent in the program",
|
|
54
|
+
"description": "Runs inside the program on its own model key. No Penguin server; nothing appears in the Web App."
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"label": "API: call a Penguin Agent",
|
|
58
|
+
"value": "Use the Agent API: call a Penguin Agent over AMSP",
|
|
59
|
+
"description": "Calls an Agent on your Penguin server. You turn on its API access and create a key; its conversations appear in the Web App."
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
````
|
|
65
|
+
|
|
66
|
+
The Web App shows the block as two buttons; the CLI and the messaging channels show it as a numbered list. The answer arrives as the user's next message, in plain text: read it like any other message and build on the way it names.
|
|
15
67
|
|
|
16
68
|
## Before you start
|
|
17
69
|
|
|
18
|
-
If the user's message only invokes this skill (e.g. "use penguin-sdk skill") without a concrete app to build, ask the user what they want to build.
|
|
70
|
+
If the user's message only invokes this skill (e.g. "use penguin-sdk skill") without a concrete app to build, ask the user what they want to build. Once the request is concrete, settle the way first (see *Ask which way first*). Then do **not** ask follow-up questions: build it end to end with that way's defaults and list the assumptions you made in your final reply.
|
|
71
|
+
|
|
72
|
+
- SDK path: a self-contained workspace project, the project default model, BM25 retrieval, a web UI styled per the web-design skill.
|
|
73
|
+
- API path: a self-contained workspace project in TypeScript on `@prismshadow/amsp` (plain HTTP when the user's program is in another language), calling the Agent the user named ("you" means this Agent) or, with none named, a new Agent created for the purpose with the agent-initialization skill.
|
|
74
|
+
|
|
75
|
+
Each path also needs one thing only the user can provide: a model credential on the SDK path (see *Keys and the data root*), and on the API path the Agent's API access and key (see *The API path*).
|
|
76
|
+
|
|
77
|
+
## The SDK path
|
|
78
|
+
|
|
79
|
+
`@prismshadow/penguin-core` is the TypeScript SDK this agent itself runs on. Use it to build your own AI apps:
|
|
80
|
+
|
|
81
|
+
- An **Agent** loads its state (prompts, tools, skills) from `<root>/<project_id>/agents/<agent_id>/`. Creating an Agent whose directory is empty initializes it with defaults.
|
|
82
|
+
- A **Session** is one conversation of an Agent inside a **Workspace** directory.
|
|
83
|
+
- `session.run()` executes one task and streams every step (thinking, text, tool calls) as OmniMessages.
|
|
19
84
|
|
|
20
|
-
|
|
85
|
+
### Project location
|
|
21
86
|
|
|
22
87
|
Create the app in the current workspace directory by default (the `CWD` value from your Environment section), as a self-contained project — do not place it under `<app_data_dir>` (PenguinHarness's app data root) or depend on any path outside the project folder. When creating the app's agent, the data root defaults **under the working directory (CWD)** too: point `createAgent({ root })` at a directory inside the project, resolved from the source file so it stays relative:
|
|
23
88
|
|
|
@@ -27,7 +92,7 @@ const agent = await createAgent({ root: path.join(import.meta.dirname, "penguin_
|
|
|
27
92
|
|
|
28
93
|
With every reference relative to the project, the user can move or copy the folder anywhere and it still runs.
|
|
29
94
|
|
|
30
|
-
|
|
95
|
+
### Keys and the data root — check before you build
|
|
31
96
|
|
|
32
97
|
**The app's Penguin data root must live inside the CWD workspace — never `~/.penguin`.** Point `createAgent({ root })` and every `penguin config ... --root <dir>` at a directory under the current working directory (e.g. `./penguin_data`); the global `~/.penguin` belongs to the person running Penguin and must never hold — or lend — the app's config or keys.
|
|
33
98
|
|
|
@@ -39,9 +104,9 @@ env | grep -oE "(DEEPSEEK|OPENAI|ANTHROPIC|GEMINI)_API_KEY" || echo none
|
|
|
39
104
|
|
|
40
105
|
**Only two sources count as a usable credential**: a vault-injected environment variable (the check above; vault keys also appear in your Vault Keys section), or a key already configured in the app's own data root (`penguin config model list --root <data_dir>`). Keys in the global `~/.penguin` or any other `.penguin` directory do **not** count — a bare `penguin config model list` (no `--root`) reads the global store, because the CLI defaults to the global root unless `--root` is given, so a key showing up there proves nothing for the app and must never be used or copied.
|
|
41
106
|
|
|
42
|
-
If neither counted source yields a key, **stop immediately and ask the user to configure one — do not start building, and do not burn turns re-checking in a loop**: have them open this agent's settings via the **gear icon** on its card (left side, Agents page) and add a model API key (e.g. `DEEPSEEK_API_KEY`) in the **key vault** tab — vault values reach your shell environment on the next task. One clear check, then hand back to the user. Build only after a credential is confirmed, or after clearly agreeing with the user to build now and verify later. Model ids to offer the user come from the penguin CLI catalog (`penguin config model add --help`) and the
|
|
107
|
+
If neither counted source yields a key, **stop immediately and ask the user to configure one — do not start building, and do not burn turns re-checking in a loop**: have them open this agent's settings via the **gear icon** on its card (left side, Agents page) and add a model API key (e.g. `DEEPSEEK_API_KEY`) in the **key vault** tab — vault values reach your shell environment on the next task. One clear check, then hand back to the user. Build only after a credential is confirmed, or after clearly agreeing with the user to build now and verify later. Model ids to offer the user come from the penguin CLI catalog (`penguin config model add --help`) and the unified-llm-api skill's id table.
|
|
43
108
|
|
|
44
|
-
|
|
109
|
+
### Setup
|
|
45
110
|
|
|
46
111
|
```bash
|
|
47
112
|
npm install @prismshadow/penguin-core tsx
|
|
@@ -51,8 +116,8 @@ If the package is not on your npm registry (it is developed in the PenguinHarnes
|
|
|
51
116
|
|
|
52
117
|
Configure a model for the app's data root, in this order — stop at the first that works:
|
|
53
118
|
|
|
54
|
-
1. `penguin config model add --root <data_dir> --provider <group> --model-id <id> --api-key <key> [--base-url <url>] [--client-type openai-chat] --set-default` — prefer `--client-type openai-chat --base-url <endpoint>` (works with any OpenAI Chat Completions compatible endpoint; exact ids in the
|
|
55
|
-
2. Environment variables cover the **credential only** (`DEEPSEEK_API_KEY`, `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, …) —
|
|
119
|
+
1. `penguin config model add --root <data_dir> --provider <group> --model-id <id> --api-key <key> [--base-url <url>] [--client-type openai-chat] --set-default` — prefer `--client-type openai-chat --base-url <endpoint>` (works with any OpenAI Chat Completions compatible endpoint; exact ids in the unified-llm-api skill). `--provider` is required: a model is always the `(provider, model_id)` pair and the group is never inferred from the id (`custom` for an endpoint outside the built-in groups).
|
|
120
|
+
2. Environment variables cover the **credential only** (`DEEPSEEK_API_KEY`, `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, …), and only for an entry whose requests go to the **vendor's own endpoint** (no `--base-url`, or the vendor's official one) — an entry with a `--base-url` of its own (a gateway, a self-hosted server) needs `--api-key`, or `createSession` refuses it. Model selection still comes from the project config, whose preset default is `deepseek-flash`. Env-only setup therefore works out of the box only with `DEEPSEEK_API_KEY`; for another vendor either run the CLI command above or pass a configured `{ provider, modelId }` pair to `createSession`.
|
|
56
121
|
|
|
57
122
|
Keep model API keys **project-local**: configure them with the penguin CLI into the app's own data root under the working directory, so the project stays self-contained and movable. When building an AI app, **always pass `--root <data_dir>` pointing at the app's data directory inside the current working directory** (the same path you give `createAgent({ root })`, e.g. `./penguin_data`) — never run `penguin config ...` without `--root`, or it writes to the global `~/.penguin/data` instead of the project. Never read, copy or fall back to model keys stored in the user's global `~/.penguin` directory — that config belongs to the person running Penguin, not to the app you are building.
|
|
58
123
|
|
|
@@ -60,7 +125,7 @@ Model config lives in one hidden file under the data root's project directory: `
|
|
|
60
125
|
|
|
61
126
|
If the user agreed to build before a credential exists, do not fake the verification: finish the build, report it as **unverified**, and point them at the key vault flow above — once a key is added, vault values reach your environment on the next task and you can run the self-test to completion.
|
|
62
127
|
|
|
63
|
-
|
|
128
|
+
### Streaming loop
|
|
64
129
|
|
|
65
130
|
The raw `run()` stream mixes model, event and session-meta payloads — always narrow with the exported guards (`isModelMessage`, `isCompleteModelMessage`, `isEventMessage`) before touching `payload.type`; accessing `msg.payload.type` directly does not typecheck.
|
|
66
131
|
|
|
@@ -99,7 +164,7 @@ session.dispose();
|
|
|
99
164
|
- Session lifetime is the app's memory model: reuse one Session for a stateful chat (context accumulates, as above), create one per request for stateless QA (the RAG recipe below); either way call `session.dispose()` when done to release background processes.
|
|
100
165
|
- An Agent's behavior is edited in its `agent_state/` files (system_config.yaml, AGENTS.md, skills/), not in code.
|
|
101
166
|
|
|
102
|
-
|
|
167
|
+
### Thinking and image messages
|
|
103
168
|
|
|
104
169
|
Modern models think before answering and accept images; the stream and the input protocol carry both — use them instead of flattening everything to text.
|
|
105
170
|
|
|
@@ -116,15 +181,15 @@ Browser flow: `<input type="file" accept="image/*">` plus paste/drag-drop → `F
|
|
|
116
181
|
|
|
117
182
|
**Other payloads worth handling** (always narrow with the guards first): `partial_tool_call` / `partial_tool_call_output` — surface as an activity line ("running `search`…") in apps that grant tools; `request_end` (event) — a non-`completed` `status` is the error signal (`auth` → ask for a key; `message` carries the failure detail; `retry_in_ms` announces a planned in-run retry, renderable as a countdown); `token_usage` (event) — session-cumulative and last-request counts, if the app shows cost; `compaction_begin` / `compaction_end` (events) — long-lived chats only, show a brief "context being compacted" notice. Everything else is safe to ignore.
|
|
118
183
|
|
|
119
|
-
|
|
184
|
+
### Wiring in the user's tools
|
|
120
185
|
|
|
121
186
|
When the app's agent must call the user's existing tools (scripts, internal CLIs, anything with an entry point), integrate them as **CLI commands** first: wrap each one as a small executable inside the project (a script under `tools/`, or the user's own binary), and describe it in the embedded agent's persona / `AGENTS.md` — name, what it does, one usage line. The agent invokes it through the built-in `exec_command` tool, so there is nothing to register: no schema to declare, arguments are flags, stdout is the result, the `approve` callback still gates every invocation, and the same command stays testable by hand.
|
|
122
187
|
|
|
123
188
|
Add an MCP server (`tools.mcpServers` in `system_config.yaml`) only when a CLI wrapper cannot express the integration — a long-lived authenticated connection, or tool schemas the model must see typed. Otherwise the CLI form is the cheaper default and keeps the project self-contained.
|
|
124
189
|
|
|
125
|
-
|
|
190
|
+
### RAG knowledge app
|
|
126
191
|
|
|
127
|
-
The default recipe when the user wants an app that answers questions over a document set ("docs QA", "knowledge base", "chat with our docs", "become an expert on X"). The core contributes the agent loop only — retrieval is app code. Default to **lexical BM25**: no extra dependencies, no embedding credential, works offline. (Semantic upgrade: embed chunks via `@prismshadow/
|
|
192
|
+
The default recipe when the user wants an app that answers questions over a document set ("docs QA", "knowledge base", "chat with our docs", "become an expert on X"). The core contributes the agent loop only — retrieval is app code. Default to **lexical BM25**: no extra dependencies, no embedding credential, works offline. (Semantic upgrade: embed chunks via `@prismshadow/mmsp` — see the unified-llm-api skill — and rank by cosine; only when an embedding-capable key is configured.)
|
|
128
193
|
|
|
129
194
|
```
|
|
130
195
|
my-app/
|
|
@@ -344,7 +409,7 @@ http.createServer(async (req, res) => {
|
|
|
344
409
|
|
|
345
410
|
**Persona** (`persona.md`) — the embedded agent's role, written per the agent-initialization skill. Shape: one role sentence ("You are an expert on X; you answer strictly from the provided context blocks"), citation and refusal rules, plain-text output (no Markdown — the output contract above), answer language follows the question.
|
|
346
411
|
|
|
347
|
-
|
|
412
|
+
### Verify before you hand over
|
|
348
413
|
|
|
349
414
|
Never declare the app done without running it:
|
|
350
415
|
|
|
@@ -357,3 +422,12 @@ Never declare the app done without running it:
|
|
|
357
422
|
5. Open the UI (or screenshot it) to confirm the layout renders.
|
|
358
423
|
|
|
359
424
|
Fix any failure and re-verify; when the app accepts image input, one verification question must include a real image. Report with backtick-wrapped relative paths (`server.ts`, `public/index.html`, …), how to start the app, and the assumptions you made.
|
|
425
|
+
|
|
426
|
+
## The API path
|
|
427
|
+
|
|
428
|
+
The program calls an Agent that lives in PenguinHarness. You write the program; the Project's owner opens the Agent to it. Read [`reference/agent-api.md`](reference/agent-api.md) before you write any code: it has the steps to hand the owner, the client code, curl, the errors and the checks. These rules hold throughout:
|
|
429
|
+
|
|
430
|
+
- **Never open an Agent yourself.** Whether an Agent is open to programs is the owner's decision, and so is everything around it: API access, keys, keyless access, the API approval mode and the server-wide switch. An Agent must not be able to expose itself. The server refuses `penguin agent api enable`, `disable`, `set`, `keys create`, `keys rm` and `server` to the token in your shell with `403 human_required`, because they take a person's sign-in. Never run them, and never sign in or mint a session to get past that refusal. Ask the user to make the change on the Agent's **API** tab, or with those commands in their own terminal after `penguin auth login`, and give them the steps. `penguin agent api status` and `keys ls` only read; use them to check.
|
|
431
|
+
- **Keep the key out of the code.** The program reads it from the `PENGUIN_AGENT_KEY` environment variable. Never write a key into source, a committed file, a log or a reply, and never ask the user to paste one into the chat.
|
|
432
|
+
- **Connection values.** The Base URL and the Agent ID come from the API tab or `penguin agent api status --agent-id <agentId>`. A local server's Base URL is `http://localhost:7364/api/amsp/v1`: `localhost`, not `127.0.0.1`, where a local server serves previews and refuses every API request with `401`. The Agent ID is `<projectId>/<agentId>`.
|
|
433
|
+
- **No data root, no model key.** The server runs the Agent on the Project's models. An SDK recipe keeps its shape on this path: the RAG app, for instance, replaces `createAgent`, `createSession` and `session.run` with an `AgentClient` run, and its persona goes into the Agent's `AGENTS.md`.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# The API path: a program that calls a Penguin Agent
|
|
2
|
+
|
|
3
|
+
Read this before you write a program that calls a Penguin Agent over the Agent API. The rules in SKILL.md, *The API path*, hold throughout. The user documentation has every detail: the [Agent API guide](https://penguin.ooo/docs/agent-api) and the [AMSP protocol](https://penguin.ooo/docs/amsp).
|
|
4
|
+
|
|
5
|
+
## 1. Hand the opening to the user
|
|
6
|
+
|
|
7
|
+
Check first. This command only reads:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
penguin agent api status --agent-id <agentId> --json
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
It prints one line of JSON: `agent` (the Agent ID), `baseUrl`, `api` (`enabled`, `open`, `approvalMode`, `keys`) and `serverEnabled`. A key's secret is never in it.
|
|
14
|
+
|
|
15
|
+
When `api.enabled` is false, or `api.keys` is empty and `api.open` is false, the program cannot run yet. Give the user these steps with the Agent's id filled in. Only the Project's owner can take them.
|
|
16
|
+
|
|
17
|
+
1. Open the Agent's settings and select the **API** tab (`/agents/<agentId>?tab=api`).
|
|
18
|
+
2. Turn on **Enable API access**.
|
|
19
|
+
3. Choose the **Approval mode for API conversations** (see the table below).
|
|
20
|
+
4. Under **Keys**, select **New key**, name it after the program, and copy the key. It is shown once.
|
|
21
|
+
5. Give the key to the program as the environment variable `PENGUIN_AGENT_KEY`.
|
|
22
|
+
|
|
23
|
+
The same steps in the user's own terminal, never in yours:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
penguin auth login
|
|
27
|
+
penguin agent api enable --agent-id <agentId> --approve <mode>
|
|
28
|
+
export PENGUIN_AGENT_KEY="$(penguin agent api keys create --agent-id <agentId> --name <program>)"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`keys create` prints the key alone on stdout, so the variable takes it without showing it. These commands change the Agent's exposure, so they take the user's sign-in: `penguin auth login` once, or `penguin auth token` on the server's machine. From your shell the server refuses them with `403 human_required`. Never sign in or mint a session to get past that.
|
|
32
|
+
|
|
33
|
+
When `serverEnabled` is false, the server's administrator has turned the Agent API off, and every request is refused with `403`. Only an administrator turns it back on, in **Settings › Server › Agent API**.
|
|
34
|
+
|
|
35
|
+
Suggest the approval mode that fits the program, and say why in one line:
|
|
36
|
+
|
|
37
|
+
| The program | Mode | What happens |
|
|
38
|
+
| --- | --- | --- |
|
|
39
|
+
| Has no one to ask: a batch job, a backend | `allow-all` (the default) | Every tool call runs, inside the sandbox |
|
|
40
|
+
| May let the agent read but nothing more | `read-only` | Read-only tools run; every other call waits for the program's answer |
|
|
41
|
+
| Shows every tool call to its own user | `always-ask` | Every call waits for the program's answer |
|
|
42
|
+
| Must never run a tool | `deny-all` | Every call is denied; the agent answers without tools |
|
|
43
|
+
|
|
44
|
+
A call that waits reaches the program as an `approval.requested` event, and the run waits, with no time limit, for an answer, an abort or a disconnect. The `@prismshadow/amsp` client answers it with `onApproval`, or with `deny` when there is none. The mode is read when an API conversation is created; a change on the tab applies to conversations created after it.
|
|
45
|
+
|
|
46
|
+
Leave **Allow keyless access** off unless the user asks for it. With it on, anything that can reach the server can run the Agent on the Project's models.
|
|
47
|
+
|
|
48
|
+
To run the program yourself, you need the key in your environment. Ask the user to add it to your key vault as `PENGUIN_AGENT_KEY`: the gear icon on your card on the Agents page, then the key vault tab. Vault values reach your shell on the next task. Until then, the program is unverified.
|
|
49
|
+
|
|
50
|
+
## 2. The connection values
|
|
51
|
+
|
|
52
|
+
| Value | Where it comes from | In the program |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| Base URL | **Connection** on the API tab, or `baseUrl` from `status` | A constant, which `PENGUIN_AGENT_URL` can override |
|
|
55
|
+
| Agent ID | **Connection** on the API tab, or `agent` from `status`: `<projectId>/<agentId>` | A constant |
|
|
56
|
+
| Key | Created by the owner, shown once | `process.env.PENGUIN_AGENT_KEY`, and nowhere else |
|
|
57
|
+
|
|
58
|
+
- A local server's Base URL is `http://localhost:7364/api/amsp/v1`; `status` prints the server's real port. Use `localhost`, never `127.0.0.1`: a local server serves previews on `127.0.0.1` and answers every API request there with `401`.
|
|
59
|
+
- Do not give the program's settings the names the harness sets inside a session: `PENGUIN_API_URL`, `PENGUIN_API_TOKEN`, `PENGUIN_PROJECT_ID`, `PENGUIN_AGENT_ID`, `PENGUIN_SESSION_ID`. They name the session's own server and Agent, and they override a vault entry of the same name.
|
|
60
|
+
|
|
61
|
+
## 3. TypeScript: `@prismshadow/amsp`
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npm install @prismshadow/amsp
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The client has no dependencies and runs in Node 24 and in current browsers. If your registry does not have the package, call the API over HTTP as in section 4.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { AgentClient, parseArguments } from "@prismshadow/amsp";
|
|
71
|
+
|
|
72
|
+
const apiKey = process.env.PENGUIN_AGENT_KEY;
|
|
73
|
+
if (!apiKey) throw new Error("Set PENGUIN_AGENT_KEY to the key from the agent's API tab.");
|
|
74
|
+
|
|
75
|
+
const client = new AgentClient({
|
|
76
|
+
baseUrl: process.env.PENGUIN_AGENT_URL ?? "http://localhost:7364/api/amsp/v1",
|
|
77
|
+
agent: "demo/coder", // <projectId>/<agentId>
|
|
78
|
+
apiKey, // the client reads no environment variable itself
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// One question, the whole answer.
|
|
82
|
+
const first = await client.ask({ input: "Summarize README.md" });
|
|
83
|
+
if (first.status !== "completed") throw new Error(`${first.status}: ${first.error?.message ?? ""}`);
|
|
84
|
+
console.log(first.text);
|
|
85
|
+
|
|
86
|
+
// The same conversation, streamed: pass its Session id back.
|
|
87
|
+
const run = client.run({
|
|
88
|
+
sessionId: first.sessionId,
|
|
89
|
+
input: "Now list its headings",
|
|
90
|
+
onApproval: (request) => {
|
|
91
|
+
const args = parseArguments(request.tool_call);
|
|
92
|
+
return request.tool_call.name === "exec_command" && args?.cmd === "ls" ? "allow" : "deny";
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
for await (const event of run) {
|
|
96
|
+
// An event without `origin` is the main conversation's; a subagent's events carry one.
|
|
97
|
+
if (event.type === "text.delta" && !event.origin) process.stdout.write(event.text);
|
|
98
|
+
}
|
|
99
|
+
const second = await run.result();
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
- `ask()` runs to the end and resolves with the result: `status`, `error`, `sessionId`, `text` (the main conversation's answer), `items`, `usage`, `sessionUsage` and `requests`. `run()` starts the run and returns it at once: iterate it once for the events, await `run.session` for the Session id, and `run.result()` for the end.
|
|
103
|
+
- **Conversations.** Keep one `sessionId` per conversation of the program, such as one per end user or chat thread, and pass it back to continue. Omit it to start a new conversation. Only the Agent's own API conversations can be continued.
|
|
104
|
+
- **Approvals.** `onApproval` is called only when the approval mode makes a call wait. Without it, or when it throws, the client answers `deny`. A person can answer the same request in the Web App; the first answer counts.
|
|
105
|
+
- **Aborting.** Abort the `signal` passed to `run()` or `ask()` to drop the connection: the server aborts the run. `run.abort()` asks the server to abort and still delivers the final `run.done`, with `status: "aborted"`.
|
|
106
|
+
- **Failures.** A refusal before the stream starts rejects with `AmspHttpError` (`status`, `code`, `message`; see section 5). After that, `result()` resolves for every run: check `status` (`completed`, `aborted`, `retryable` or `fatal`) and `error`. A stream that breaks before `run.done` rejects with `AmspStreamError`.
|
|
107
|
+
- **Unknown events** are passed through. Switch on `event.type` with a default branch.
|
|
108
|
+
- **A web app** keeps the key on its own server. The page posts to the app's server, which runs the Agent and relays the `text.delta` events to the page over SSE, aborting through `signal` when the page disconnects: the shape of the RAG recipe's `server.ts`. A key inside a page is readable by everyone who loads the page.
|
|
109
|
+
|
|
110
|
+
## 4. Any language: HTTP and curl
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
BASE="${PENGUIN_AGENT_URL:-http://localhost:7364/api/amsp/v1}"
|
|
114
|
+
|
|
115
|
+
# Start a conversation. The answer streams back as it is produced.
|
|
116
|
+
curl -N "$BASE/agents/demo/coder/runs" \
|
|
117
|
+
-H "Authorization: Bearer $PENGUIN_AGENT_KEY" -H "Content-Type: application/json" \
|
|
118
|
+
-d '{"input":"Summarize README.md"}'
|
|
119
|
+
|
|
120
|
+
# Continue it with the session_id that the first event, run.started, carried.
|
|
121
|
+
curl -N "$BASE/agents/demo/coder/runs" \
|
|
122
|
+
-H "Authorization: Bearer $PENGUIN_AGENT_KEY" -H "Content-Type: application/json" \
|
|
123
|
+
-d '{"session_id":"<session_id>","input":"Now list its headings"}'
|
|
124
|
+
|
|
125
|
+
# Answer an approval.requested event while its run is still streaming.
|
|
126
|
+
curl -X POST "$BASE/sessions/<session_id>/approvals/<tool_call_id>" \
|
|
127
|
+
-H "Authorization: Bearer $PENGUIN_AGENT_KEY" -H "Content-Type: application/json" \
|
|
128
|
+
-d '{"decision":"allow"}'
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
To read the stream in your own code:
|
|
132
|
+
|
|
133
|
+
- Each event is one `data: <JSON>` line followed by a blank line. After the last event comes `data: [DONE]`. A line that starts with `:` is a keep-alive comment, sent after 15 seconds of silence: skip it.
|
|
134
|
+
- The first event is `run.started`, with the `session_id`. The last is `run.done`, with `status`, `error` and `usage`. The answer is the assistant `text.done` events without an `origin`, or their `text.delta` fragments as they arrive.
|
|
135
|
+
- Skip every event `type` you do not know.
|
|
136
|
+
- `POST <Base URL>/sessions/<session_id>/abort` aborts a run and keeps its stream open until `run.done`.
|
|
137
|
+
|
|
138
|
+
## 5. Errors
|
|
139
|
+
|
|
140
|
+
A request refused before the stream gets an HTTP status and `{"error": {"code": "…", "message": "…"}}`. Once the stream has started, `run.done` carries the error instead.
|
|
141
|
+
|
|
142
|
+
| Status | `code` | Usually | What to do |
|
|
143
|
+
| --- | --- | --- | --- |
|
|
144
|
+
| 400 | `bad_request` | A malformed body | The message names the field |
|
|
145
|
+
| 401 | `unauthorized` | No key, a wrong or deleted key, or `127.0.0.1` in the Base URL | Check `PENGUIN_AGENT_KEY` and that the Base URL uses `localhost` |
|
|
146
|
+
| 403 | `agent_api_disabled` | The administrator turned the Agent API off | Ask the user to have an administrator turn it on |
|
|
147
|
+
| 404 | `agent_not_found` | API access is off, the Agent ID is wrong, or the key belongs to another Agent | Check with `penguin agent api status`, then ask the owner |
|
|
148
|
+
| 404 | `session_not_found` | The `session_id` is not one of this Agent's API conversations | Start a new conversation |
|
|
149
|
+
| 409 | `task_in_progress`, `compacting` | The conversation is still busy | Wait for its `run.done`: one run per conversation at a time |
|
|
150
|
+
| 429 | `too_many_runs` | The Agent already has 4 conversations running, Web App ones included | Retry after `Retry-After` seconds |
|
|
151
|
+
|
|
152
|
+
## 6. Verify before you hand over
|
|
153
|
+
|
|
154
|
+
1. `penguin agent api status --agent-id <agentId> --json` shows `api.enabled` true and at least one key.
|
|
155
|
+
2. The key is in your environment: `test -n "$PENGUIN_AGENT_KEY" && echo set`. Never print the value.
|
|
156
|
+
3. Run the program once with a real input. The run ends with `status` `completed`, and the answer appears.
|
|
157
|
+
4. Tell the user where to find the conversation: **Settings › Archived chats** in the Web App, marked with the API icon. An API conversation stays archived until someone unarchives it, which moves it into the sidebar.
|
|
158
|
+
|
|
159
|
+
When step 1 or 2 is not done, finish the program anyway, report it as **unverified**, and end your reply with the owner's steps from section 1. Report the files with relative paths, how to run the program, the Agent ID it calls, the approval mode it expects, and your assumptions.
|