-
Notifications
You must be signed in to change notification settings - Fork 9
docs: define llm and actor input/output interfaces #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Myriad-Dreamin
wants to merge
30
commits into
EmaFanClub:main
Choose a base branch
from
Myriad-Dreamin:io-interface
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
6aa02bb
docs: draft llm client and actor input/output interfaces.
Myriad-Dreamin 14d1e2a
fix: valid id
Myriad-Dreamin c86370c
dev: improve actor docs
Myriad-Dreamin a653bd9
fix: format
Myriad-Dreamin 27e7116
Update packages/ema/src/concept/actor.ts
Myriad-Dreamin d79e670
Update packages/ema/src/concept/llm.ts
Myriad-Dreamin 958ea4c
draft
Myriad-Dreamin 1c57e86
feat: finish agent interface
Myriad-Dreamin 7032898
dev: design scheduler
Myriad-Dreamin 87fe8b2
dev: space
Myriad-Dreamin ad0d3fa
dev: agent arg
Myriad-Dreamin 48cfe16
dev: split cron function
Myriad-Dreamin 2fff0e6
dev: agent events
Myriad-Dreamin 6d216a4
fix: examples
Myriad-Dreamin 0ce8eee
fix: simplify examples
Myriad-Dreamin 3683b96
dev: move accessor
Myriad-Dreamin 19c5682
fix: comments
Myriad-Dreamin 7293b79
Update packages/ema/src/concept/llm.ts
Myriad-Dreamin c87e3ad
dev: export agent state
Myriad-Dreamin 6d41d28
dev: update description
Myriad-Dreamin 2c4f3c7
dev: update description
Myriad-Dreamin f7b9c6c
dev: add comments
Myriad-Dreamin 6acadc6
dev: update example
Myriad-Dreamin 9c05868
dev: update example
Myriad-Dreamin da19975
dev: add stateless api
Myriad-Dreamin a2ae025
dev: update interface
Myriad-Dreamin 99136c3
dev: update interface
Myriad-Dreamin e7cad00
feat: synchronized documents
Disviel 67a04ee
fix: align concept task typing with non-generic agent
Disviel 2b599e2
Merge branch 'main' into io-interface
Disviel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import type { EventEmitter } from "node:events"; | ||
| import type { Content as InputContent } from "../schema"; | ||
| import type { AgentEventName, AgentEvent, AgentEventUnion } from "./llm"; | ||
|
|
||
| /** | ||
| * The scope information for the actor. | ||
| */ | ||
| export interface ActorScope { | ||
| actorId: number; | ||
| userId: number; | ||
| conversationId: number; | ||
| } | ||
|
|
||
| /** | ||
| * A batch of actor inputs in one request. | ||
| */ | ||
| export type ActorInputs = InputContent[]; | ||
|
|
||
| /** | ||
| * The status of the actor. | ||
| */ | ||
| export type ActorStatus = "preparing" | "running" | "idle"; | ||
|
|
||
| /** | ||
| * A message from the actor. | ||
| */ | ||
| export interface ActorMessageEvent { | ||
| /** The kind of the event. */ | ||
| kind: "message"; | ||
| /** The content of the message. */ | ||
| content: string; | ||
| } | ||
|
|
||
| /** | ||
| * An event forwarded from the agent. | ||
| */ | ||
| export interface ActorAgentEvent { | ||
| /** The kind of the event. */ | ||
| kind: AgentEventName; | ||
| /** The content of the message. */ | ||
| content: AgentEventUnion; | ||
| } | ||
|
|
||
| /** | ||
| * The event map for actor events. | ||
| */ | ||
| export interface ActorEventMap { | ||
| message: [ActorMessageEvent]; | ||
| agent: [ActorAgentEvent]; | ||
| } | ||
|
|
||
| /** | ||
| * Union of actor event names. | ||
| */ | ||
| export type ActorEventName = keyof ActorEventMap; | ||
|
|
||
| /** | ||
| * Type mapping of actor event names to their corresponding event data types. | ||
| */ | ||
| export type ActorEvent<K extends ActorEventName> = ActorEventMap[K][0]; | ||
|
|
||
| /** | ||
| * Union type of all actor event contents. | ||
| */ | ||
| export type ActorEventUnion = ActorEvent<ActorEventName>; | ||
|
|
||
| /** | ||
| * Constant mapping of actor event names for iteration. | ||
| */ | ||
| export const ActorEventNames: Record<ActorEventName, ActorEventName> = { | ||
| message: "message", | ||
| agent: "agent", | ||
| }; | ||
|
|
||
| /** | ||
| * Event source interface for the actor. | ||
| */ | ||
| export interface ActorEventSource { | ||
| on<K extends ActorEventName>( | ||
| event: K, | ||
| handler: (content: ActorEvent<K>) => void, | ||
| ): this; | ||
| off<K extends ActorEventName>( | ||
| event: K, | ||
| handler: (content: ActorEvent<K>) => void, | ||
| ): this; | ||
| once<K extends ActorEventName>( | ||
| event: K, | ||
| handler: (content: ActorEvent<K>) => void, | ||
| ): this; | ||
| emit<K extends ActorEventName>(event: K, content: ActorEvent<K>): boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Typed event emitter for actor events. | ||
| */ | ||
| export type ActorEventsEmitter = EventEmitter<ActorEventMap> & ActorEventSource; | ||
|
|
||
| /** | ||
| * Type guard that narrows an actor event to a specific agent event (or any agent event). | ||
| */ | ||
| export function isAgentEvent<K extends AgentEventName | undefined>( | ||
| event: ActorEventUnion, | ||
| kind?: K, | ||
| ): event is ActorAgentEvent & | ||
| (K extends AgentEventName | ||
| ? { kind: K; content: AgentEvent<K> } | ||
| : ActorAgentEvent) { | ||
| if (!event) return false; | ||
| if (event.kind === "message") return false; | ||
| return kind ? event.kind === kind : true; | ||
| } | ||
|
|
||
| /** | ||
| * A facade of the actor functionalities between the server (system) and the agent (actor). | ||
| */ | ||
| export declare class ActorWorker { | ||
| /** | ||
| * Event emitter for actor events. | ||
| */ | ||
| readonly events: ActorEventsEmitter; | ||
| /** | ||
| * Enqueues inputs and runs the agent sequentially for this actor. | ||
| * @param inputs - Batch of user inputs for a single request. | ||
| * @param addToBuffer - Whether to persist inputs to conversation buffer. | ||
| */ | ||
| work(inputs: ActorInputs, addToBuffer?: boolean): Promise<void>; | ||
| /** | ||
| * Reports whether the actor is currently preparing or running. | ||
| */ | ||
| isBusy(): boolean; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import type { Message } from "../schema"; | ||
|
|
||
| /** | ||
| * Compatibility-only types for legacy actor implementation in this branch. | ||
| * These are intentionally not exported from `concept/index.ts`. | ||
| */ | ||
|
|
||
| export interface ActorStateStorage { | ||
| getState(): Promise<ActorState>; | ||
| updateState(state: ActorState): Promise<void>; | ||
| } | ||
|
|
||
| export interface ActorState { | ||
| memoryBuffer: Message[]; | ||
| } | ||
|
|
||
| export interface ActorMemory { | ||
| search(keywords: string[]): Promise<SearchActorMemoryResult>; | ||
| addShortTermMemory(item: ShortTermMemory): Promise<void>; | ||
| addLongTermMemory(item: LongTermMemory): Promise<void>; | ||
| } | ||
|
|
||
| export interface SearchActorMemoryResult { | ||
| items: LongTermMemory[]; | ||
| } | ||
|
|
||
| export interface ShortTermMemory { | ||
| kind: "year" | "month" | "day"; | ||
| os: string; | ||
| statement: string; | ||
| createdAt: number; | ||
| } | ||
|
|
||
| export interface LongTermMemory { | ||
| index0: string; | ||
| index1: string; | ||
| keywords: string[]; | ||
| os: string; | ||
| statement: string; | ||
| createdAt: number; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /** | ||
| * Conceptual architecture of EverMemoryArchive (aligned with memory runtime design). | ||
| * | ||
| * High-level flow: | ||
| * 1. UI sends user input to server APIs. | ||
| * 2. Server resolves `(user, actor, conversation)` and routes to an `ActorWorker`. | ||
| * 3. `ActorWorker` serializes buffer writes, queues inputs, and may interrupt an in-flight run. | ||
| * 4. `Agent` executes an LLM+tool loop and emits structured events. | ||
| * 5. `MemoryManager` persists conversation buffer and memory records, then injects memory into prompts. | ||
| * 6. `Scheduler` drives foreground/background jobs (for reminders and memory organization). | ||
| * | ||
| * ```mermaid | ||
| * graph TD | ||
| * subgraph UI["UI Layer"] | ||
| * WebUI["Web UI"] | ||
| * Clients["Other Clients"] | ||
| * end | ||
| * | ||
| * subgraph Runtime["EMA Runtime"] | ||
| * Server["Server"] | ||
| * Actor["ActorWorker"] | ||
| * Agent["Agent (LLM + Tools Loop)"] | ||
| * Memory["MemoryManager"] | ||
| * Scheduler["Scheduler"] | ||
| * end | ||
| * | ||
| * subgraph Storage["Storage Layer"] | ||
| * Mongo["MongoDB"] | ||
| * Lance["LanceDB (Vector Search)"] | ||
| * end | ||
| * | ||
| * subgraph LLM["LLM Providers"] | ||
| * OpenAI["OpenAI-Compatible"] | ||
| * Google["Google GenAI"] | ||
| * end | ||
| * | ||
| * UI --> Server | ||
| * Server --> Actor | ||
| * Actor --> Agent | ||
| * Agent --> LLM | ||
| * Actor --> Memory | ||
| * Memory --> Storage | ||
| * Server --> Scheduler | ||
| * Scheduler --> Actor | ||
| * ``` | ||
| * | ||
| * @module @internals/concept | ||
| */ | ||
|
|
||
| export * from "./actor"; | ||
| export * from "./llm"; | ||
| export * from "./storage"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.