Skip to content

Commit

Permalink
Merge pull request #9 from statelyai/davidkpiano/tools
Browse files Browse the repository at this point in the history
Add tool choice
  • Loading branch information
davidkpiano authored Feb 14, 2024
2 parents d1e0259 + 869fede commit 55e81d7
Show file tree
Hide file tree
Showing 10 changed files with 1,227 additions and 466 deletions.
31 changes: 31 additions & 0 deletions .changeset/rude-mice-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
'@statelyai/agent': patch
---

Add `adapter.fromTool(…)`, which creates an actor that chooses agent logic based on a input.

```ts
const actor = adapter.fromTool(() => 'Draw me a picture of a donut', {
// tools
makeIllustration: {
description: 'Makes an illustration',
run: async (input) => {
/* ... */
},
inputSchema: {
/* ... */
},
},
getWeather: {
description: 'Gets the weather',
run: async (input) => {
/* ... */
},
inputSchema: {
/* ... */
},
},
});

//...
```
14 changes: 7 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${file}",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": ["${workspaceFolder}/**/*.js"]
"name": "Debug Current Test File",
"autoAttachChildProcesses": true,
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": ["run", "${relativeFile}"],
"smartStep": true,
"console": "integratedTerminal"
}
]
}
2 changes: 1 addition & 1 deletion examples/joke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const getTopic = fromPromise(async () => {
return topic;
});

const decide = adapter.fromEventChoice(
const decide = adapter.fromEvent(
(lastRating: string) =>
`Choose what to do next, given the previous rating of the joke: ${lastRating}`
);
Expand Down
2 changes: 1 addition & 1 deletion examples/ticTacToe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const initialContext = {
events: [],
} satisfies typeof schemas.types.context;

const bot = adapter.fromEventChoice(
const bot = adapter.fromEvent(
({ context }: { context: typeof schemas.types.context }) => `
You are playing a game of tic tac toe. This is the current game state. The 3x3 board is represented by a 9-element array. The first element is the top-left cell, the second element is the top-middle cell, the third element is the top-right cell, the fourth element is the middle-left cell, and so on. The value of each cell is either null, x, or o. The value of null means that the cell is empty. The value of x means that the cell is occupied by an x. The value of o means that the cell is occupied by an o.
Expand Down
2 changes: 1 addition & 1 deletion examples/weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const machine = setup({
types: schemas.types,
actors: {
getWeather,
decide: adapter.fromEventChoice(
decide: adapter.fromEvent(
(input: string) =>
`Decide what to do based on the given input, which may or may not be a location: ${input}`
),
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"openai": "^4.24.1",
"ts-node": "^10.9.2",
"tsup": "^8.0.1",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"vitest": "^1.2.2"
},
"publishConfig": {
"access": "public"
Expand Down
Loading

0 comments on commit 55e81d7

Please sign in to comment.