Skip to content

Commit e2d7bf2

Browse files
committed
chat improvements
1 parent 541e18f commit e2d7bf2

File tree

10 files changed

+113
-93
lines changed

10 files changed

+113
-93
lines changed

llms.txt

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export type UUID = `${string}-${string}-${string}-${string}-${string}`;
1919
export function asUUID(id: string): UUID
2020
export interface Content {
2121
thought?: string;
22-
plan?: string;
2322
text?: string;
2423
actions?: string[];
2524
providers?: string[];

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"start:app": "turbo run start --filter=./packages/app",
88
"dev": "turbo run dev --filter=./packages/the-org",
99
"build:docs": "turbo run build --filter=@elizaos/docs",
10-
"build": "turbo run build --filter=!@elizaos/docs",
10+
"build": "turbo run build --filter=@elizaos/client && turbo run build --filter=!@elizaos/docs",
1111
"clean": "rm -rf dist .turbo node_modules .turbo-tsconfig.json tsconfig.tsbuildinfo bun.lock* && turbo run clean --filter=./packages/*",
1212
"lint": "turbo run lint --filter=./packages/* && prettier --write . && prettier --check .",
1313
"pre-commit": "bun run scripts/pre-commit-lint.js",

packages/cli/src/displayBanner.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ export function displayBanner(version: string | null = null, hideBanner = false)
1212
const red = '\x1b[38;5;196m';
1313
let versionColor = lightblue;
1414

15+
// assume __dirname doesnt exist
16+
const __dirname = path.resolve(import.meta.dirname, '..');
17+
1518
if (!version) {
16-
const packageJsonPath = path.join(process.cwd(), 'package.json');
19+
const packageJsonPath = path.join(__dirname, 'package.json');
1720
if (!fs.existsSync(packageJsonPath)) {
1821
} else {
1922
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));

packages/cli/src/server/api/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ export function setupSocketIO(
153153

154154
// Add optional fields only if they exist in the original content
155155
if (content.thought) broadcastData.thought = content.thought;
156-
if (content.plan) broadcastData.plan = content.plan;
157156
if (content.actions) broadcastData.actions = content.actions;
158157

159158
// Log exact broadcast data

packages/client/src/components/chat.tsx

+104-64
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ import type { IAttachment } from '@/types';
1515
import type { Content, UUID } from '@elizaos/core';
1616
import { AgentStatus } from '@elizaos/core';
1717
import { useQueryClient } from '@tanstack/react-query';
18-
import { Activity, Database, PanelRight, Paperclip, Send, Terminal, X } from 'lucide-react';
18+
import {
19+
Activity,
20+
ChevronRight,
21+
Database,
22+
PanelRight,
23+
Paperclip,
24+
Send,
25+
Terminal,
26+
X,
27+
} from 'lucide-react';
1928
import { useEffect, useRef, useState, useCallback } from 'react';
2029
import AIWriter from 'react-aiwriter';
2130
import { AgentActionViewer } from './action-viewer';
@@ -29,6 +38,7 @@ import { useAutoScroll } from './ui/chat/hooks/useAutoScroll';
2938
import { Tabs, TabsContent, TabsList, TabsTrigger } from './ui/tabs';
3039
import { Tooltip, TooltipContent, TooltipTrigger } from './ui/tooltip';
3140
import { AgentMemoryViewer } from './memory-viewer';
41+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@radix-ui/react-collapsible';
3242

3343
const SOURCE_NAME = 'client_chat';
3444

@@ -49,6 +59,7 @@ function MessageContent({
4959
agentId: UUID;
5060
isLastMessage: boolean;
5161
}) {
62+
console.log('message', message);
5263
// Only log message details in development mode
5364
if (import.meta.env.DEV) {
5465
console.log(`[Chat] Rendering message from ${message.name}:`, {
@@ -60,58 +71,88 @@ function MessageContent({
6071
}
6172

6273
return (
63-
<div className="flex flex-col">
64-
<ChatBubbleMessage
65-
isLoading={message.isLoading}
66-
{...(message.name === USER_NAME ? { variant: 'sent' } : {})}
67-
>
68-
{message.name === USER_NAME ? (
69-
message.text
70-
) : isLastMessage && message.name !== USER_NAME ? (
71-
<AIWriter>{message.text}</AIWriter>
72-
) : (
73-
message.text
74-
)}
75-
{/* Attachments */}
76-
<div>
77-
{message.attachments?.map((attachment: IAttachment) => (
78-
<div className="flex flex-col gap-1 mt-2" key={`${attachment.url}-${attachment.title}`}>
79-
<img
80-
alt="attachment"
81-
src={attachment.url}
82-
width="100%"
83-
height="100%"
84-
className="w-64 rounded-md"
85-
/>
86-
<div className="flex items-center justify-between gap-4">
87-
<span />
88-
<span />
89-
</div>
74+
<ChatBubbleMessage
75+
isLoading={message.isLoading}
76+
{...(message.name === USER_NAME ? { variant: 'sent' } : {})}
77+
{...(!message.text ? { className: 'bg-transparent' } : {})}
78+
>
79+
<div className="flex flex-col w-full m-0 p-0">
80+
{message.name !== USER_NAME && (
81+
<>
82+
<div className="flex justify-end mb-2 absolute top-2 right-2">
83+
{message.text && !message.isLoading ? (
84+
<div className="flex items-center gap-4">
85+
<CopyButton text={message.text} />
86+
<ChatTtsButton agentId={agentId} text={message.text} />
87+
</div>
88+
) : (
89+
<div />
90+
)}
9091
</div>
91-
))}
92+
{message.text && message.thought && (
93+
<Collapsible className="mb-1">
94+
<CollapsibleTrigger className="flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors group">
95+
<ChevronRight className="h-4 w-4 transition-transform group-data-[state=open]:rotate-90" />
96+
Thought Process
97+
</CollapsibleTrigger>
98+
<CollapsibleContent className="pl-5 pt-1">
99+
<Badge variant="outline" className="text-xs">
100+
{message.thought}
101+
</Badge>
102+
</CollapsibleContent>
103+
</Collapsible>
104+
)}
105+
</>
106+
)}
107+
</div>
108+
109+
{message.name === USER_NAME ? (
110+
message.text
111+
) : isLastMessage && message.name !== USER_NAME ? (
112+
<AIWriter>{message.text}</AIWriter>
113+
) : (
114+
message.text
115+
)}
116+
117+
{!message.text && message.thought && (
118+
<>
119+
{message.name === USER_NAME ? (
120+
message.thought
121+
) : isLastMessage && message.name !== USER_NAME ? (
122+
<AIWriter>
123+
<span className="italic text-muted-foreground">{message.thought}</span>
124+
</AIWriter>
125+
) : (
126+
<span className="italic text-muted-foreground">{message.thought}</span>
127+
)}
128+
</>
129+
)}
130+
131+
{message.text && message.actions && (
132+
<div className="mt-2">
133+
Actions: <span className="font-bold">{message.actions}</span>
92134
</div>
93-
</ChatBubbleMessage>
94-
<div className="flex items-center gap-4 justify-between w-full mt-1">
95-
{message.text && !message.isLoading ? (
96-
<div className="flex items-center gap-1">
97-
<CopyButton text={message.text} />
98-
<ChatTtsButton agentId={agentId} text={message.text} />
135+
)}
136+
137+
{message.attachments?.map((attachment: IAttachment) => (
138+
<div className="flex flex-col gap-1" key={`${attachment.url}-${attachment.title}`}>
139+
<img
140+
alt="attachment"
141+
src={attachment.url}
142+
width="100%"
143+
height="100%"
144+
className="w-64 rounded-md"
145+
/>
146+
<div className="flex items-center justify-between gap-4">
147+
<span />
148+
<span />
99149
</div>
100-
) : null}
101-
<div
102-
className={cn([
103-
message.isLoading ? 'mt-2' : '',
104-
'flex items-center justify-between gap-4 select-none',
105-
])}
106-
>
107-
{message.thought ? <Badge variant="outline">{message.thought}</Badge> : null}
108-
{message.plan ? <Badge variant="outline">{message.plan}</Badge> : null}
109-
{message.createdAt ? (
110-
<ChatBubbleTimestamp timestamp={moment(message.createdAt).format('LT')} />
111-
) : null}
112150
</div>
113-
</div>
114-
</div>
151+
))}
152+
{message.text && message.createdAt && (
153+
<ChatBubbleTimestamp timestamp={moment(message.createdAt).format('LT')} />
154+
)}
155+
</ChatBubbleMessage>
115156
);
116157
}
117158

@@ -412,23 +453,22 @@ export default function Page({ agentId }: { agentId: UUID }) {
412453
>
413454
<ChatBubble
414455
variant={isUser ? 'sent' : 'received'}
415-
className={`flex flex-row items-center gap-2 ${
416-
isUser ? 'flex-row-reverse' : ''
417-
}`}
456+
className={`flex flex-row items-end gap-2 ${isUser ? 'flex-row-reverse' : ''}`}
418457
>
419-
<Avatar className="size-8 border rounded-full select-none">
420-
<AvatarImage
421-
src={
422-
isUser
423-
? '/user-icon.png'
424-
: agentData?.settings?.avatar
425-
? agentData?.settings?.avatar
426-
: '/elizaos-icon.png'
427-
}
428-
/>
458+
{message.text && !isUser && (
459+
<Avatar className="size-8 border rounded-full select-none mb-2">
460+
<AvatarImage
461+
src={
462+
isUser
463+
? '/user-icon.png'
464+
: agentData?.settings?.avatar
465+
? agentData?.settings?.avatar
466+
: '/elizaos-icon.png'
467+
}
468+
/>
469+
</Avatar>
470+
)}
429471

430-
{isUser && <AvatarFallback>U</AvatarFallback>}
431-
</Avatar>
432472
<MessageContent
433473
message={message}
434474
agentId={agentId}

packages/client/src/lib/socketio-manager.ts

-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class SocketIOManager extends EventEmitter {
7979
textType: typeof data.text,
8080
textLength: data.text ? data.text.length : 0,
8181
hasThought: 'thought' in data,
82-
hasPlan: 'plan' in data,
8382
hasActions: 'actions' in data,
8483
additionalKeys: Object.keys(data).filter(
8584
(k) =>
@@ -91,7 +90,6 @@ class SocketIOManager extends EventEmitter {
9190
'createdAt',
9291
'source',
9392
'thought',
94-
'plan',
9593
'actions',
9694
].includes(k)
9795
),

packages/core/src/bootstrap.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,15 @@ const messageReceivedHandler = async ({
230230
// Retry if missing required fields
231231
let retries = 0;
232232
const maxRetries = 3;
233-
while (
234-
retries < maxRetries &&
235-
(!responseContent?.thought || !responseContent?.plan || !responseContent?.actions)
236-
) {
233+
while (retries < maxRetries && (!responseContent?.thought || !responseContent?.actions)) {
237234
const response = await runtime.useModel(ModelType.TEXT_SMALL, {
238235
prompt,
239236
});
240237

241238
responseContent = parseJSONObjectFromText(response) as Content;
242239

243240
retries++;
244-
if ((!responseContent?.thought || !responseContent?.plan) && !responseContent?.actions) {
241+
if (!responseContent?.thought && !responseContent?.actions) {
245242
logger.warn('*** Missing required fields, retrying... ***');
246243
}
247244
}
@@ -256,7 +253,6 @@ const messageReceivedHandler = async ({
256253
}
257254

258255
if (responseContent) {
259-
responseContent.plan = responseContent.plan?.trim();
260256
responseContent.inReplyTo = createUniqueUuid(runtime, message.id);
261257

262258
responseMessages = [
@@ -277,7 +273,6 @@ const messageReceivedHandler = async ({
277273
agentId: runtime.agentId,
278274
content: {
279275
thought: responseContent.thought,
280-
plan: responseContent.plan,
281276
actions: responseContent.actions,
282277
providers: responseContent.providers,
283278
},
@@ -474,7 +469,6 @@ const postGeneratedHandler = async ({
474469
source: 'twitter',
475470
channelType: ChannelType.FEED,
476471
thought: jsonResponse.thought || '',
477-
plan: jsonResponse.plan || '',
478472
type: 'post',
479473
},
480474
roomId: message.roomId,

packages/core/src/prompts.ts

+1-11
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ export const formatMessages = ({
208208
messages: Memory[];
209209
entities: Entity[];
210210
}) => {
211-
const newestMessageWithContentPlan = messages.find(
212-
(message: Memory) => (message.content as Content).plan
213-
);
214211
const messageStrings = messages
215212
.reverse()
216213
.filter((message: Memory) => message.entityId)
@@ -254,13 +251,8 @@ export const formatMessages = ({
254251
} (${formattedName}'s actions: ${messageActions.join(', ')})`
255252
: null;
256253

257-
const planString =
258-
newestMessageWithContentPlan?.id === message.id
259-
? `(${formattedName}'s plan: ${newestMessageWithContentPlan?.content?.plan})`
260-
: null;
261-
262254
// for each thought, action, text or attachment, add a new line, with text first, then thought, then action, then attachment
263-
const messageString = [textString, thoughtString, planString, actionString, attachmentString]
255+
const messageString = [textString, thoughtString, actionString, attachmentString]
264256
.filter(Boolean)
265257
.join('\n');
266258

@@ -320,14 +312,12 @@ First, think about what you want to do next and plan your actions. Then, write t
320312
"actions" should be an array of the actions {{agentName}} plans to take based on the thought (if none, use IGNORE, if simply responding with text, use REPLY)
321313
"providers" should be an optional array of the providers that {{agentName}} will use to have the right context for responding and acting
322314
"evaluators" should be an optional array of the evaluators that {{agentName}} will use to evaluate the conversation after responding
323-
"plan" should be explanation of the message you plan to send, the actions you plan to take, and the data providers you plan to use.
324315
These are the available valid actions: {{actionNames}}
325316
326317
Response format should be formatted in a valid JSON block like this:
327318
\`\`\`json
328319
{
329320
"thought": "<string>",
330-
"plan": "<string>",
331321
"actions": ["<string>", "<string>", ...],
332322
"providers": ["<string>", "<string>", ...]
333323
}

packages/core/src/types.ts

-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ export interface Content {
2525
/** The agent's internal thought process */
2626
thought?: string;
2727

28-
/** The agent's plan for the next message */
29-
plan?: string;
30-
3128
/** The main text content visible to users */
3229
text?: string;
3330

packages/the-org/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elizaos/the-org",
3-
"version": "1.0.0-alpha.38",
3+
"version": "1.0.0-alpha.65",
44
"main": "dist/index.js",
55
"module": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)