Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: statelyai/agent
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.7
Choose a base ref
...
head repository: statelyai/agent
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: next
Choose a head ref
Loading
Showing with 11,277 additions and 4,150 deletions.
  1. +5 −0 .changeset/calm-beans-talk.md
  2. +5 −0 .changeset/cyan-carpets-perform.md
  3. +5 −0 .changeset/fast-donkeys-argue.md
  4. +17 −0 .changeset/grumpy-dolphins-think.md
  5. +9 −0 .changeset/light-hats-drive.md
  6. +5 −0 .changeset/long-guests-explode.md
  7. +10 −0 .changeset/nice-pants-rule.md
  8. +5 −0 .changeset/odd-kiwis-compare.md
  9. +5 −0 .changeset/old-jobs-check.md
  10. +5 −0 .changeset/old-teachers-tap.md
  11. +13 −0 .changeset/pink-eagles-deliver.md
  12. +25 −0 .changeset/pre.json
  13. +7 −0 .changeset/quiet-turtles-do.md
  14. +23 −0 .changeset/smart-yaks-pull.md
  15. +16 −0 .changeset/sweet-clouds-mix.md
  16. +5 −0 .changeset/swift-mangos-rush.md
  17. +5 −0 .changeset/tough-ways-rhyme.md
  18. +0 −3 .env.template
  19. +11 −11 .github/actions/ci-setup/action.yml
  20. +17 −6 .github/workflows/release.yml
  21. +1 −1 .gitignore
  22. +18 −1 .vscode/launch.json
  23. +281 −0 CHANGELOG.md
  24. +797 −0 architecture.tldr
  25. +57 −0 examples/chatbot-alt.ts
  26. +70 −0 examples/chatbot.ts
  27. +38 −0 examples/cot.ts
  28. +107 −0 examples/customer-service-sim.ts
  29. +114 −0 examples/email.ts
  30. +81 −0 examples/example.ts
  31. +66 −0 examples/executor.ts
  32. +94 −0 examples/goal.ts
  33. +26 −14 examples/helpers/helpers.ts
  34. +136 −128 examples/joke.ts
  35. +122 −0 examples/jugs.ts
  36. +123 −0 examples/learn-from-feedback.ts
  37. +103 −0 examples/multi.ts
  38. 0 examples/multiAgentCollaboration.ts
  39. +318 −0 examples/newspaper.ts
  40. +103 −0 examples/number.ts
  41. +0 −128 examples/numberGuesser.ts
  42. +104 −0 examples/raffle.ts
  43. +62 −0 examples/rewoo.ts
  44. +137 −0 examples/river-crossing.ts
  45. +28 −0 examples/sandbox.ts
  46. +71 −0 examples/serverless.ts
  47. +44 −0 examples/simple.ts
  48. +118 −0 examples/summary.ts
  49. +147 −0 examples/support.ts
  50. +168 −133 examples/ticTacToe.ts
  51. +137 −0 examples/todo.ts
  52. +100 −0 examples/tutor.ts
  53. +120 −0 examples/verify.ts
  54. +139 −0 examples/weather-agent.ts
  55. +73 −55 examples/weather.ts
  56. +49 −0 examples/wiki.ts
  57. +178 −0 examples/word.ts
  58. +0 −156 examples/wordGuesser.ts
  59. +41 −17 package.json
  60. +3,332 −2,806 pnpm-lock.yaml
  61. +55 −30 readme.md
  62. +0 −217 src/adapter.test.ts
  63. +0 −298 src/adapters/openai.ts
  64. +0 −8 src/agent.ts
  65. +346 −0 src/decide.test.ts
  66. +129 −0 src/decide.ts
  67. +877 −0 src/expert.test.ts
  68. +629 −0 src/expert.ts
  69. +5 −3 src/index.ts
  70. +91 −0 src/middleware.ts
  71. +47 −0 src/mockModel.ts
  72. +48 −0 src/policies/chainOfThoughtPolicy.ts
  73. +3 −0 src/policies/index.ts
  74. +91 −0 src/policies/shortestPathPolicy.test.ts
  75. +178 −0 src/policies/shortestPathPolicy.ts
  76. +105 −0 src/policies/toolPolicy.ts
  77. +10 −39 src/schemas.ts
  78. +21 −0 src/templates/defaultText.ts
  79. +138 −0 src/text.ts
  80. +483 −46 src/types.ts
  81. +115 −46 src/utils.ts
  82. +1 −1 tsconfig.json
  83. +9 −3 vitest.config.ts
5 changes: 5 additions & 0 deletions .changeset/calm-beans-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@statelyai/agent': major
---

"Strategy" has been renamed to "policy", and "score" has been renamed to "reward".
5 changes: 5 additions & 0 deletions .changeset/cyan-carpets-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@statelyai/agent': patch
---

The `name` field in `createAgent({ name: '...' })` has been renamed to `id`.
5 changes: 5 additions & 0 deletions .changeset/fast-donkeys-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@statelyai/agent": patch
---

The `description` field in `createAgent({ description: '...' })` is now used for the `system` prompt in agent decision making when a `system` prompt is not provided.
17 changes: 17 additions & 0 deletions .changeset/grumpy-dolphins-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@statelyai/agent': minor
---

planner -> strategy
agent.addPlan -> agent.addDecision
agent.getPlans -> agent.getDecisions

The word "strategy" is now used instead of "planner" to make it more clear what the agent is doing: it uses a strategy to make decisions. The method `agent.addPlan(…)` has been renamed to `agent.addDecision(…)` and `agent.getPlans(…)` has been renamed to `agent.getDecisions(…)` to reflect this change. Additionally, you specify the `strategy` instead of the `planner` when creating an agent:

```diff
const agent = createAgent({
- planner: createSimplePlanner(),
+ strategy: createSimpleStrategy(),
...
});
```
9 changes: 9 additions & 0 deletions .changeset/light-hats-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@statelyai/agent': major
---

- `agent.generateText(…)` is removed in favor of using the AI SDK's `generateText(…)` function with a wrapped model.
- `agent.streamText(…)` is removed in favor of using the AI SDK's `streamText(…)` function with a wrapped model.
- Custom adapters are removed for now, but may be re-added in future releases. Using the AI SDK is recommended for now.
- Correlation IDs are removed in favor of using [OpenTelemetry with the AI SDK](https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#telemetry).
- The `createAgentMiddleware(…)` function was introduced to facilitate agent message history. You can also use `agent.wrap(model)` to wrap a model with Stately Agent middleware.
5 changes: 5 additions & 0 deletions .changeset/long-guests-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@statelyai/agent": major
---

Set ai as peer dependency
10 changes: 10 additions & 0 deletions .changeset/nice-pants-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@statelyai/agent': major
---

- The `machine` and `machineHash` properties were removed from `AgentObservation` and `AgentObservationInput`
- The `defaultOptions` property was removed from `Agent`
- `AgentDecideOptions` was renamed to `AgentDecideInput`
- The `execute` property was removed from `AgentDecideInput`
- The `episodeId` optional property was added to `AgentDecideInput`, `AgentObservationInput`, and `AgentFeedbackInput`
- `decisionId` was added to `AgentObservationInput` and `AgentFeedbackInput`
5 changes: 5 additions & 0 deletions .changeset/odd-kiwis-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@statelyai/agent': minor
---

You can now add **insights** for observations made. Insights are additional context about the observations made, which can be useful for agent decision making.
5 changes: 5 additions & 0 deletions .changeset/old-jobs-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@statelyai/agent': minor
---

You can specify `maxAttempts` in `agent.decide({ maxAttempts: 5 })`. This will allow the agent to attempt to make a decision up to the specified number of `maxAttempts` before giving up. The default value is `2`.
5 changes: 5 additions & 0 deletions .changeset/old-teachers-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@statelyai/agent': minor
---

For feedback, the `goal`, `observationId`, and `attributes` are now required, and `feedback` and `reward` are removed since they are redundant.
13 changes: 13 additions & 0 deletions .changeset/pink-eagles-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@statelyai/agent': patch
---

The `score` is now required for feedback:

```ts
agent.addFeedback({
score: 0.5,
goal: 'Win the game',
observationId: '...',
});
```
25 changes: 25 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"mode": "pre",
"tag": "next",
"initialVersions": {
"@statelyai/agent": "1.1.6"
},
"changesets": [
"calm-beans-talk",
"cyan-carpets-perform",
"fast-donkeys-argue",
"grumpy-dolphins-think",
"light-hats-drive",
"long-guests-explode",
"nice-pants-rule",
"odd-kiwis-compare",
"old-jobs-check",
"old-teachers-tap",
"pink-eagles-deliver",
"quiet-turtles-do",
"smart-yaks-pull",
"sweet-clouds-mix",
"swift-mangos-rush",
"tough-ways-rhyme"
]
}
7 changes: 7 additions & 0 deletions .changeset/quiet-turtles-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@statelyai/agent': major
---

The `state` can no longer be specified in `agent.interact(...)`, since the actual state value is already observed and passed to the `strategy` function.

The `context` provided to agent decision functions, like `agent.decide({ context })` and in `agent.interact(...)`, is now used solely to override the `state.context` provided to the prompt template.
23 changes: 23 additions & 0 deletions .changeset/smart-yaks-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@statelyai/agent': minor
---

You can specify `allowedEvents` in `agent.decide(...)` to allow from a list of specific events to be sent to the agent. This is useful when using `agent.decide(...)` without a state machine.

```ts
const agent = createAgent({
// ...
events: {
PLAY: z.object({}).describe('Play a move'),
SKIP: z.object({}).describe('Skip a move'),
FORFEIT: z.object({}).describe('Forfeit the game'),
},
});

// ...
const decision = await agent.decide({
// Don't allow the agent to send `FORFEIT` or other events
allowedEvents: ['PLAY', 'SKIP'],
// ...
});
```
16 changes: 16 additions & 0 deletions .changeset/sweet-clouds-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@statelyai/agent': patch
---

The entire observed `state` must be provided, instead of only `context`, for any agent decision making functions:

```ts
agent.interact(actor, (obs) => {
// ...
return {
goal: 'Some goal',
// instead of context
state: obs.state,
};
});
```
5 changes: 5 additions & 0 deletions .changeset/swift-mangos-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@statelyai/agent": patch
---

Remove `goal` from feedback input
5 changes: 5 additions & 0 deletions .changeset/tough-ways-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@statelyai/agent": minor
---

Add `score` and `comment` fields for feedback
3 changes: 0 additions & 3 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

# Get your OpenAI API key from: https://platform.openai.com/signup/
OPENAI_API_KEY="sk-..."

# Get your Tavily API key from: https://app.tavily.com/
TAVILY_API_KEY="tvly-..."
22 changes: 11 additions & 11 deletions .github/actions/ci-setup/action.yml
Original file line number Diff line number Diff line change
@@ -7,18 +7,18 @@ runs:
- uses: actions/setup-node@v4
with:
node-version: 20.x

- name: install pnpm
run: npm i pnpm@latest -g
shell: bash

- name: Get pnpm store directory
- name: Setup npmrc
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
shell: bash
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: setup pnpm config
run: pnpm config set store-dir $PNPM_CACHE_FOLDER
shell: bash

- run: pnpm install
shell: bash
23 changes: 17 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -11,9 +11,9 @@ permissions: {}
jobs:
release:
permissions:
contents: write # to create release (changesets/action)
contents: write # to create release (changesets/action)
issues: write # to post issue comments (changesets/action)
pull-requests: write # to create pull request (changesets/action)
pull-requests: write # to create pull request (changesets/action)

if: github.repository == 'statelyai/agent'

@@ -22,10 +22,21 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/ci-setup

- name: Create Release Pull Request or Publish to npm
- name: checkout code repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: setup node.js
uses: actions/setup-node@v3
with:
node-version: 20
- name: install pnpm
run: npm i pnpm@latest -g
- name: setup pnpm config
run: pnpm config set store-dir $PNPM_CACHE_FOLDER
- name: install dependencies
run: pnpm install
- name: create and publish versions
uses: changesets/action@v1
with:
publish: pnpm run release
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ out

# Nuxt.js build / generate output
.nuxt
dist
dist/

# Gatsby files
.cache/
19 changes: 18 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -7,11 +7,28 @@
"request": "launch",
"name": "Debug Current Test File",
"autoAttachChildProcesses": true,
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
"skipFiles": ["<node_internals>/**", "**/node_modules/**", "examples/**"],
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": ["run", "${relativeFile}"],
"smartStep": true,
"console": "integratedTerminal"
},
{
"type": "node",
"request": "launch",
"name": "Debug Current File",
"program": "${file}",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ts-node",
"runtimeArgs": ["--transpile-only", "-r", "dotenv/config"],
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"sourceMaps": true,
"smartStep": true,
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**"
],
"console": "integratedTerminal"
}
]
}
Loading