diff --git a/docs/docs/faq.md b/docs/docs/faq.md index 7071cda3b6..2679234299 100644 --- a/docs/docs/faq.md +++ b/docs/docs/faq.md @@ -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. diff --git a/packages/client-direct/src/api.ts b/packages/client-direct/src/api.ts index f74174e445..6d5ac569f5 100644 --- a/packages/client-direct/src/api.ts +++ b/packages/client-direct/src/api.ts @@ -11,6 +11,7 @@ import { import { REST, Routes } from "discord.js"; import { DirectClient } from "."; +import { stringToUuid } from "@elizaos/core"; export function createApiRouter( agents: Map, @@ -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; }