Skip to content

Conversation

@threepointone
Copy link
Contributor

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

[email protected]

Patch Changes

  • #37 ff0679f Thanks @threepointone! - Agent::initialState

    You can now set an initial state for an agent

    type State = {
      counter: number;
      text: string;
      color: string;
    };
    
    class MyAgent extends Agent<Env, State> {
      initialState = {
        counter: 0,
        text: "",
        color: "#3B82F6",
      };
    
      doSomething() {
        console.log(this.state); // {counter: 0, text: "", color: "#3B82F6"}, if you haven't set the state yet
      }
    }

    As before, this gets synced to useAgent, so you can do:

    const [state, setState] = useState<State>();
    const agent = useAgent<State>({
      agent: "my-agent",
      onStateUpdate: (state) => {
        setState(state);
      },
    });

[email protected]

Patch Changes

@threepointone threepointone merged commit 6cd6b96 into main Feb 27, 2025
1 check passed
@threepointone threepointone deleted the changeset-release/main branch February 27, 2025 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant