Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/prompt-context-feature-undocumented.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@generata/core": patch
---

docs: document promptContext feature for injecting file context into agent prompts
27 changes: 27 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,33 @@ defineWorkflow({
});
```

## Prompt context

Every LLM-backed agent (`worker`, `critic`, `planner`, `dispatcher`) accepts a `promptContext` array on its `defineAgent` options. Each entry names a file to inject into the agent's prompt as an `<context file="...">...</context>` XML block, prepended before the task body. The engine - not the agent author - owns the framing, so templates never need to say "you have X above".

```ts
defineAgent({
type: "worker",
description: "...",
modelTier: "standard",
promptContext: [
{ filepath: "NOTES.md" }, // required, full file
{ filepath: "CHANGELOG.md", head: 40 }, // first 40 lines only
{ filepath: "logs/run.log", tail: 200 }, // last 200 lines only
{ filepath: "memory/progress.txt", optional: true }, // skipped if missing
{ filepath: ({ slug }) => `projects/${slug}/SPEC.md` }, // resolved per-call
],
prompt: `...`,
});
```

| Field | Type | Behaviour |
| :--------- | :-------------------------------------------- | :------------------------------------------------------------------------ |
| `filepath` | `string \| (vars: ContextVars) => string` | Resolved relative to the run's working directory. Function form receives the same strict variables as `prompt`, so it can interpolate workflow inputs / step outputs. |
| `head` | `number` (optional) | Keep only the first N lines of the file. |
| `tail` | `number` (optional) | Keep only the last N lines. Combine with `head` to take a head-then-tail slice. |
| `optional` | `boolean` (optional) | If `true` and the file is missing, the entry is skipped silently - no tag, no warning. If `false` (default) and the file is missing, the engine renders `<context file="..." status="missing" />` and prints a `[context] <agent>: '<path>' not found` warning to stderr. Use `optional: true` for files that are expected to be absent on fresh systems (e.g. `memory/progress.txt`). |

## Running workflows from code

`@generata/core` exposes `runWorkflow` and `runAgent` so you can drive any workflow or agent from your own TypeScript without going through the CLI. This is the primitive for loops, batch jobs, or wrapping generata in a larger script.
Expand Down
18 changes: 18 additions & 0 deletions packages/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,24 @@ export default defineAgent<{ slug: string }>(({ slug }) => ({

The filename becomes the agent or workflow name. Every `.ts` under `agents/` is scanned recursively and classified by its default export - `defineAgent` makes it an agent, `defineWorkflow` makes it a workflow. Workflows belong in `agents/workflows/` by convention (used by `standup` and `coding`); the `starter` template uses flat `agents/` placement, which works equally well for projects with a single workflow.

## Injecting file context into prompts

Agents can declare `promptContext` to read files into their prompt without hand-rolling `read` tool calls. The [`coding`](./coding) template uses this to feed `NOTES.md` into the spec creator:

```ts
defineAgent({
type: "worker",
// ...
promptContext: [
{ filepath: "NOTES.md" },
{ filepath: "memory/progress.txt", optional: true },
],
prompt: `...`,
});
```

Each entry supports `head` / `tail` line caps and an `optional` flag - when `optional: true`, a missing file is silently skipped; otherwise the engine injects `<context file="..." status="missing" />` and warns to stderr. Full field reference in [`@generata/core` README](../core/README.md#prompt-context).

## The manifest

`generata.template.json` is the only required file. Minimal example:
Expand Down
Loading