Skip to content

Commit

Permalink
Merge branch 'develop' into tcm-trimTokens
Browse files Browse the repository at this point in the history
  • Loading branch information
tcm390 authored Dec 31, 2024
2 parents 0064242 + 20090bf commit 6ca727a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Eliza's architecture consists of several interconnected components:
- **Agents**: These are the core elements that represent individual AI personalities. Agents operate within a runtime environment and interact with various platforms.
- **Actions**: Actions are predefined behaviors that agents can execute in response to messages, enabling them to perform tasks and interact with external systems.
- **Clients**: Clients act as interfaces between agents and specific platforms, such as Discord, Twitter, and Telegram. They handle platform-specific message formats and communication protocols.
- **Plugins**: Plugins are modular way to extend the core functionality with additional features, actions, evaluators, and providers. They are self-contained modules that can be easily added or removed to customize your agent's capabilities
- **Providers**: Providers supply agents with contextual information, including time awareness, user relationships, and data from external sources.
- **Evaluators**: These modules assess and extract information from conversations, helping agents track goals, build memory, and maintain context awareness.
- **Character Files**: These JSON files define the personality, knowledge, and behavior of each AI agent.
Expand Down
62 changes: 62 additions & 0 deletions packages/client-direct/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {

import { REST, Routes } from "discord.js";
import { DirectClient } from ".";
import { stringToUuid } from "@elizaos/core";

export function createApiRouter(
agents: Map<string, AgentRuntime>,
Expand Down Expand Up @@ -121,5 +122,66 @@ export function createApiRouter(
}
});

router.get("/agents/:agentId/:roomId/memories", async (req, res) => {
const agentId = req.params.agentId;
const roomId = stringToUuid(req.params.roomId);
let runtime = agents.get(agentId);

// if runtime is null, look for runtime with the same name
if (!runtime) {
runtime = Array.from(agents.values()).find(
(a) => a.character.name.toLowerCase() === agentId.toLowerCase()
);
}

if (!runtime) {
res.status(404).send("Agent not found");
return;
}

try {
const memories = await runtime.messageManager.getMemories({
roomId,
});
const response = {
agentId,
roomId,
memories: memories.map((memory) => ({
id: memory.id,
userId: memory.userId,
agentId: memory.agentId,
createdAt: memory.createdAt,
content: {
text: memory.content.text,
action: memory.content.action,
source: memory.content.source,
url: memory.content.url,
inReplyTo: memory.content.inReplyTo,
attachments: memory.content.attachments?.map(
(attachment) => ({
id: attachment.id,
url: attachment.url,
title: attachment.title,
source: attachment.source,
description: attachment.description,
text: attachment.text,
contentType: attachment.contentType,
})
),
},
embedding: memory.embedding,
roomId: memory.roomId,
unique: memory.unique,
similarity: memory.similarity,
})),
};

res.json(response);
} catch (error) {
console.error("Error fetching memories:", error);
res.status(500).json({ error: "Failed to fetch memories" });
}
});

return router;
}

0 comments on commit 6ca727a

Please sign in to comment.