Prerequisite

A running Scoopika API endpoint. see this page.

This guide shows how to run agents with long-term memory by using sessions. This works on both server-side and client-side.

In your server-side Scoopika initialization, you can pass a remote store ID that you can create here to have persistent memory and chat sessions, otherwise Scoopika will use an in-memory store (not persistent).

All data in remote memory stores is encrypted and never accessed by our team!

Create session

Let’s create a new session, in this case We’ll create a session for a user with the ID “SCOOP” so we can then list SCOOP’s sessions. You can use this approach to create sessions for specific users in your app based on their IDs.

// On Server-side
const session = await scoopika.newSession({
	user_id: "SCOOP"
});

// Or Client-side
const session = await client.store.newSession({
	user_id: "SCOOP"
});

Run agent

Now we can pass that session’s id to each agent run to save the run to that session, example:

await agent.run({
	options: {
		session_id: session.id
	},
	inputs: {
		message: "Hello, I'm Kais",
	}
});

Notice that we passed the session_id as the session’s ID we previously created, so now we can run the agent again and it will remember was we said earlier:

await agent.run({
	options: {
		session_id: session.id
	},
	inputs: {
		message: "Who am I?",
	}
});

Get session messages

Now we can check that session’s messages (history, it contains the user request and agent response):

// On Server-side
await scoopika.getSessionMessages(session.id);

// Or Client-side
await client.store.getSessionMessages(session.id);

List user sessions

and we can list SCOOP’s sessions, and it will return the IDs of sessions that SCOOP owns:

// On Server-side
await scoopika.listUserSessions(session.id);

// Or Client-side
await client.store.listUserSessions(session.id);

Delete session

You can also delete a session if you want to:

// On Server-side
await scoopika.deleteSession(session.id);

// Or Client-side
await client.store.deleteSession(session.id);

See how easy and simple that is, history is managed for you, you just pass sessions IDs to runs!