-
Notifications
You must be signed in to change notification settings - Fork 9
feat: implement the interruption in chat and performed some refactoring #147
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements chat interruption functionality and performs substantial refactoring of the agent and actor architecture. The main goal is to allow users to interrupt ongoing agent responses with new messages, enabling more natural conversational flow.
Changes:
- Adds abort mechanism to Agent class using AbortController and AbortSignal to stop LLM calls mid-execution
- Refactors Actor to use a queue-based processing model with state resumption after interruption
- Introduces BufferMessage class for managing conversational history with timestamps and context metadata
- Adds dayjs library for time formatting in memory buffer
- Updates UI to allow message submission while agent is running (removes loading state from input controls)
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 19 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds dayjs@1.11.19 dependency and updates eslint resolver references |
| packages/ema/package.json | Adds dayjs dependency |
| packages/ema/src/schema.ts | Adds EmaMessage type to Message union for distinguishing EMA-originated messages |
| packages/ema/src/memory/memory.ts | Adds BufferMessage class for managing timestamped conversation history and updates ActorState interface |
| packages/ema/src/db/base.ts | Adds "week" granularity option to ShortTermMemoryEntity |
| packages/ema/src/agent.ts | Major refactoring: removes token management/summarization logic, adds abort support, introduces AgentState and callback-based run model |
| packages/ema/src/actor.ts | Implements queue-based processing with interruption support, adds buildSystemPrompt, and manages buffer writes |
| packages/ema/src/llm/base.ts | Adds signal parameter to support abort operations |
| packages/ema/src/llm/client.ts | Passes signal parameter through to underlying client |
| packages/ema/src/llm/openai_client.ts | Implements abort signal support for OpenAI API calls |
| packages/ema/src/llm/google_client.ts | Implements abort signal support for Google Gemini API calls |
| packages/ema/src/retry.ts | Adds abort error detection to prevent retrying aborted requests |
| packages/ema/src/server.ts | Passes userId to ActorWorker constructor |
| packages/ema/src/tools/ema_reply_tool.ts | Removes pretty-printing from JSON output (removes null, 2 formatting) |
| packages/ema/src/tests/skills/memory.spec.ts | Updates test to pass userId parameter to ActorWorker |
| packages/ema/config/system_prompt.md | Complete rewrite with detailed role-playing instructions and memory buffer integration |
| packages/ema-ui/src/app/chat/page.tsx | Removes loading state from input controls and adds auto-scroll to latest message |
| packages/ema-ui/src/app/chat/page.module.css | Adds custom scrollbar styling and messagesEnd anchor |
| packages/ema-ui/src/app/api/actor/input/route.ts | Updates API schema from ActorInput to Content type |
| packages/ema/src/_run_actor.ts | Deleted - removes standalone actor runner script |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 19 out of 20 changed files in this pull request and generated 16 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
packages/ema/src/retry.ts:139
- The
isAbortErrorfunction checks for the error message containing "aborted" usingincludes(), which might be too broad and could match unrelated errors. Consider making this check more specific to avoid false positives. For example, an error message like "The data was abbreviated" could incorrectly match this condition.
}
if (lastException) {
throw lastException;
}
throw new Error("Unknown error");
};
return descriptor;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 19 out of 20 changed files in this pull request and generated 16 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 23 out of 24 changed files in this pull request and generated 4 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 25 out of 26 changed files in this pull request and generated 9 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 26 out of 27 changed files in this pull request and generated 16 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Close #139
Close #146
Close #148
This pull request introduces several improvements and refactorings across the EMA UI and core packages. The most significant changes include a refactor of the chat input schema, enhancements to the chat UI's scrolling behavior and accessibility, updates to the system prompt for more immersive character roleplay, and improvements to the event streaming and LLM client interfaces.
API and Schema Refactoring:
Contenttype withtypeandtextfields, replacing the previousActorInputstructure withkindandcontent. This change affects the API contract and related documentation and example usage. [1] [2] [3] [4]Chat UI/UX Improvements:
System Prompt and Character Roleplay:
Event Streaming and Typing:
ActorAgentEventtype instead of the previousActorResponse/ActorEvent, and filtered foremaReplyReceivedevents only. [1] [2] F4ca933dL4R1)Core Library and Miscellaneous:
dayjsas a dependency for date handling._run_actor.tsscript, cleaning up the codebase.