agent
agent copied to clipboard
Create state-machine-powered LLM agents using XState
Stately Agent (alpha)
- Read the documentation
- See the examples directory for working examples.
Installation
Install openai
, and @statelyai/agent
:
pnpm install openai @statelyai/agent
Usage
Work in progress. For now, see the examples:
-
Joke generator
- Demonstrates
agent.fromChatCompletion(...)
to generate a joke and provide a joke rating - Demonstrates
agent.fromEvent(...)
to choose whether to keep generating jokes or stop
- Demonstrates
-
Tic-tac-toe
- Demonstrates
agent.fromEvent(...)
to have an agent play itself in a game of tic-tac-toe with precise events - Demonstrates
agent.fromChatCompletionStream(...)
to produce a game report at the end of the game
- Demonstrates
-
Weather
- Demonstrates using Tavily as an external API
- Demonstrates
agent.fromEvent(...)
to only use Tavily to get the weather if the user provides a valid location
Examples
First, clone this repo locally. To run the examples in this repo, create a .env
file at the root of the repo with the following contents:
OPENAI_API_KEY="your-openai-api-key"
Then, install the dependencies (npm install
) and run the examples:
pnpm run example joke
# or:
# pnpm run example ticTacToe