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
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"tidy-agents-run-anywhere",
"trajectory-matchers",
"typed-tools-union-output-core-helpers",
"validate-machine-input",
"versioned-trace-schema",
"workflow-json-schema-drift"
]
Expand Down
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# @statelyai/agent

## 2.0.0-alpha.15

### Minor Changes

- [#88](https://github.com/statelyai/agent/pull/88) [`d857a8a`](https://github.com/statelyai/agent/commit/d857a8ae4a16b155d4694f8f556dca55b124c7ce) Thanks [@davidkpiano](https://github.com/davidkpiano)! - **Machine input is validated against its schema, and defaulted fields are optional at the call site.**

XState's `schemas` are types only — it never validates, and it resolves `schemas.input` to one type shared by `createActor`'s `input` option and the `context: ({ input })` factory. A field declared with a default was therefore both absent at runtime and required at the call site.

`runAgent`/`createAgentActor` now validate `options.input` against the machine's declared input schema before the actor starts: defaults are filled and transforms applied, and the resolved value is what reaches the actor, the replayable event log, and the `run.start` trace — so a replay reproduces the run even if a default is computed. Invalid input throws an `AgentError` with code `invalid-machine-input` (like a mismatched resume snapshot; the actor never starts). Omitting `input` entirely still skips validation.

```ts
const agent = setupAgent({
schemas: createAgentSchemas({
context: z.object({ topic: z.string(), rounds: z.number() }),
input: z.object({ topic: z.string(), rounds: z.number().default(3) }),
}),
});

const machine = agent.createMachine({
// `rounds` arrives filled in — no `?? 3` restating the default here
context: ({ input }) => ({ topic: input.topic, rounds: input.rounds }),
// ...
});

// `rounds` is optional at the call site; `topic` (no default) is not
await runAgent(machine, { input: { topic: "otters" } });
```

Standard Schema throughout — no validation library is referenced, so this works with whatever the machine was declared with.

Types: `runAgent`'s `input` is now `AgentInputFrom<TMachine>`, which reads the schema's pre-validation side (`~standard.types.input`) while the context factory keeps the validated side. Machines reached through `.provide(...)` lose the brand and fall back to xstate's `InputFrom`. New exported type helpers: `AgentInputFrom`, `InferInput`.

## 2.0.0-alpha.14

### Minor Changes
Expand Down
7 changes: 7 additions & 0 deletions demo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @statelyai/agent-demo

## 0.0.1-alpha.3

### Patch Changes

- Updated dependencies [[`d857a8a`](https://github.com/statelyai/agent/commit/d857a8ae4a16b155d4694f8f556dca55b124c7ce)]:
- @statelyai/agent@2.0.0-alpha.15

## 0.0.1-alpha.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@statelyai/agent-demo",
"version": "0.0.1-alpha.2",
"version": "0.0.1-alpha.3",
"private": true,
"type": "module",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions examples/cloudflare-agent-host/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @statelyai/example-cloudflare-agent-host

## 0.0.1-alpha.3

### Patch Changes

- Updated dependencies [[`d857a8a`](https://github.com/statelyai/agent/commit/d857a8ae4a16b155d4694f8f556dca55b124c7ce)]:
- @statelyai/agent@2.0.0-alpha.15

## 0.0.1-alpha.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/cloudflare-agent-host/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@statelyai/example-cloudflare-agent-host",
"version": "0.0.1-alpha.2",
"version": "0.0.1-alpha.3",
"private": true,
"type": "module",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions examples/cloudflare-workers-ai-host/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @statelyai/example-cloudflare-workers-ai-host

## 0.0.1-alpha.3

### Patch Changes

- Updated dependencies [[`d857a8a`](https://github.com/statelyai/agent/commit/d857a8ae4a16b155d4694f8f556dca55b124c7ce)]:
- @statelyai/agent@2.0.0-alpha.15

## 0.0.1-alpha.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/cloudflare-workers-ai-host/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@statelyai/example-cloudflare-workers-ai-host",
"version": "0.0.1-alpha.2",
"version": "0.0.1-alpha.3",
"private": true,
"type": "module",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions examples/next-host/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @statelyai/example-next-host

## 0.0.1-alpha.3

### Patch Changes

- Updated dependencies [[`d857a8a`](https://github.com/statelyai/agent/commit/d857a8ae4a16b155d4694f8f556dca55b124c7ce)]:
- @statelyai/agent@2.0.0-alpha.15

## 0.0.1-alpha.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/next-host/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@statelyai/example-next-host",
"version": "0.0.1-alpha.2",
"version": "0.0.1-alpha.3",
"private": true,
"type": "module",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions examples/tanstack-ai-stream/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @statelyai/example-tanstack-ai-stream

## 0.0.1-alpha.3

### Patch Changes

- Updated dependencies [[`d857a8a`](https://github.com/statelyai/agent/commit/d857a8ae4a16b155d4694f8f556dca55b124c7ce)]:
- @statelyai/agent@2.0.0-alpha.15

## 0.0.1-alpha.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/tanstack-ai-stream/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@statelyai/example-tanstack-ai-stream",
"version": "0.0.1-alpha.2",
"version": "0.0.1-alpha.3",
"private": true,
"type": "module",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions examples/tanstack-start-host/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @statelyai/example-tanstack-start-host

## 0.0.1-alpha.3

### Patch Changes

- Updated dependencies [[`d857a8a`](https://github.com/statelyai/agent/commit/d857a8ae4a16b155d4694f8f556dca55b124c7ce)]:
- @statelyai/agent@2.0.0-alpha.15

## 0.0.1-alpha.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/tanstack-start-host/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@statelyai/example-tanstack-start-host",
"version": "0.0.1-alpha.2",
"version": "0.0.1-alpha.3",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@statelyai/agent",
"version": "2.0.0-alpha.14",
"version": "2.0.0-alpha.15",
"description": "Make invalid agent actions impossible. Agent logic as state machines: deterministic, inspectable, resumable, runs anywhere.",
"type": "module",
"main": "dist/index.cjs",
Expand Down