agent icon indicating copy to clipboard operation
agent copied to clipboard

Version Packages

Open github-actions[bot] opened this issue 1 year ago • 0 comments

This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

Releases

@statelyai/[email protected]

Minor Changes

  • #26 2d63f30 Thanks @davidkpiano! - The createAgent(…) function now returns agent actor logic instead of the state machine actor logic. That means its return value can now be used directly in actors for a state machine, and it will perform tool calls and choose the correct event to send back to the machine:

    import { createAgent } from "../src";
    import { z } from "zod";
    import { setup, createActor } from "xstate";
    import OpenAI from "openai";
    
    const openai = new OpenAI({
      apiKey: process.env.OPENAI_API_KEY,
    });
    
    const agent = createAgent(openai, {
      model: "gpt-3.5-turbo-16k-0613",
      events: {
        "agent.thought": z.object({
          text: z.string().describe("The text of the thought"),
        }),
      },
    });
    
    const machine = setup({
      actors: { agent },
    }).createMachine({
      initial: "thinking",
      states: {
        thinking: {
          invoke: {
            src: "agent",
            input: "Think about a random topic, and then share that thought.",
          },
          on: {
            "agent.thought": {
              actions: ({ event }) => console.log(event.text),
              target: "thought",
            },
          },
        },
        thought: {
          type: "final",
        },
      },
    });
    
    const actor = createActor(machine).start();
    

    See the examples directory for more detailed examples

Patch Changes

  • #26 3f00f5e Thanks @davidkpiano! - defineEvents was removed. Use the events property in createAgent({ … }) instead:

    import { z } from "zod";
    import { createAgent } from "@statelyai/agent";
    
    const agent = createAgent({
      model: "gpt-4-1106-preview",
      events: {
        "agent.getWeather": z.object({
          location: z.string().describe("The location to get the weather for"),
        }),
        "agent.reportWeather": z.object({
          location: z
            .string()
            .describe("The location the weather is being reported for"),
          highF: z.number().describe("The high temperature today in Fahrenheit"),
          lowF: z.number().describe("The low temperature today in Fahrenheit"),
          summary: z.string().describe("A summary of the weather conditions"),
        }),
        "agent.doSomethingElse": z
          .object({})
          .describe(
            "Do something else, because the user did not provide a location"
          ),
      },
    });
    
  • #28 dbdea98 Thanks @davidkpiano! - Reduces API to one function: createAgent(…). This creates an agent that:

    • Is actor logic for an agent that makes decisions based on a goal
    • Has .fromText(…) and .fromTextStream(…) helpers
    • Wraps the ai library

github-actions[bot] avatar May 02 '24 17:05 github-actions[bot]