Skip to content

Commit fb28022

Browse files
committed
feat: sequential chat
1 parent 14dc5a8 commit fb28022

10 files changed

Lines changed: 76 additions & 56 deletions

File tree

api/agentok_api/templates/start_chat.j2

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,33 @@
22

33
{% if initial_chat_targets | length > 1 %}
44
# Sequential Chats
5-
# TODO: The input messsage is ignored, I guess it should be in the first element?
6-
chat_result = node_{{ first_converser['id'] }}.initiate_chats(
5+
chat_results = node_{{ first_converser['id'] }}.initiate_chats(
76
[
8-
{%- for target in initial_chat_targets -%}
7+
{%- for target in initial_chat_targets %}
98
{
109
"recipient": node_{{ target['node']['id'] }},
11-
{%- if target['chat_options'].message %}
12-
"message": "{{ target.chat_options.message }}",
10+
{%- if loop.first %}
11+
"message": args.message,
12+
{%- elif target['chat_options'].instructions %}
13+
"message": "{{ target.chat_options.instructions }}",
1314
{%- endif %}
1415
{%- if target['chat_options'].max_turns %}
1516
"max_turns": {{ target.chat_options.max_turns }},
1617
{%- endif %}
1718
{%- if target['chat_options'].summary_method %}
1819
"summary_method": "{{ target.chat_options.summary_method }}",
1920
{%- endif %}
21+
{%- if target['chat_options'].summary_prompt %}
22+
"summary_prompt": "{{ target.chat_options.summary_prompt }}",
23+
{%- endif %}
2024
}{% if not loop.last %},{% endif %}
21-
{%- endfor -%}
25+
{%- endfor %}
2226
]
2327
)
28+
29+
# Sequential Chat Results
30+
31+
2432
{%- elif initial_chat_targets | length == 1 %}
2533
{%- if initial_chat_targets[0].node['type'] == 'nestedchat' %}
2634
# Nested Chat
@@ -31,7 +39,7 @@ reply = node_{{ first_converser['id'] }}.generate_reply(
3139
# Talk to one single agent
3240
chat_result = node_{{ first_converser['id'] }}.initiate_chat(
3341
node_{{ initial_chat_targets[0].node['id'] }},
34-
{%- if initial_chat_targets and initial_chat_targets[0] and 'data' in initial_chat_targets[0] and initial_chat_targets[0]['data'].class in ['RetrieveUserProxyAgent', 'MathUserProxyAgent'] %}
42+
{%- if initial_chat_targets and initial_chat_targets[0] and 'data' in initial_chat_targets[0] and initial_chat_targets[0]['data'].class_type in ['RetrieveUserProxyAgent', 'MathUserProxyAgent'] %}
3543
problem=args.message,
3644
{%- else %}
3745
message=args.message,

frontend/src/components/chat/chat-pane.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { Loading } from '@/components/loader';
1313
import { ScrollArea } from '@/components/ui/scroll-area';
1414
import { Button } from '../ui/button';
1515
import { Badge } from '../ui/badge';
16-
import { nanoid } from 'nanoid';
1716

1817
interface ChatPaneProps {
1918
projectId: number;
@@ -64,7 +63,7 @@ export const ChatPane = ({ projectId, chatId }: ChatPaneProps) => {
6463

6564
// Subscribe to chat_messages
6665
const messagesChannel: RealtimeChannel = supabase
67-
.channel(`chat_messasges_${nanoid()}`)
66+
.channel(`chat_messasges_${genId()}`)
6867
.on(
6968
'postgres_changes',
7069
{

frontend/src/components/flow/config/assistant.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export const AssistantConfig = ({ nodeId, data, className, ...props }: any) => {
77
data={data}
88
className={className}
99
toolScene={'llm'}
10-
optionsDisabled={['human_input_mode']}
1110
{...props}
1211
/>
1312
);

frontend/src/components/flow/config/converse-config.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ export const ConverseConfig = ({ edgeId, data }: any) => {
7878
<ScrollArea>
7979
<div className="flex flex-col gap-4 p-2">
8080
<GenericOption
81+
type="text"
82+
key={`${edgeId}-instructions`}
83+
nodeId={edgeId}
84+
data={data}
85+
rows={2}
86+
name="instructions"
87+
label="Instructions"
88+
placeholder="Enter a prompt for the instructions. This can be overridden with command arguments."
89+
/>
90+
<GenericOption
91+
key={`${edgeId}-mode`}
8192
type="select"
8293
nodeId={edgeId}
8394
data={data}
@@ -89,12 +100,46 @@ export const ConverseConfig = ({ edgeId, data }: any) => {
89100
]}
90101
/>
91102
<GenericOption
103+
key={`${edgeId}-allow-repeat`}
92104
type="check"
93105
nodeId={edgeId}
94106
data={data}
95107
name="allow_repeat"
96108
label="Allow Repeat"
97109
/>
110+
<GenericOption
111+
key={`${edgeId}-summary-method`}
112+
type="select"
113+
nodeId={edgeId}
114+
data={data}
115+
name="summary_method"
116+
label="Summary Method"
117+
options={[
118+
{ value: 'last_msg', label: 'Last Message' },
119+
{ value: 'reflection_with_llm', label: 'Reflection with LLM' },
120+
]}
121+
/>
122+
<GenericOption
123+
key={`${edgeId}-summary-prompt`}
124+
type="text"
125+
nodeId={edgeId}
126+
data={data}
127+
rows={3}
128+
name="summary_prompt"
129+
label="Summary Prompt"
130+
placeholder="Enter a prompt for the summary."
131+
/>
132+
<GenericOption
133+
key={`${edgeId}-max-turns`}
134+
type="range"
135+
nodeId={edgeId}
136+
data={data}
137+
name="max_turns"
138+
label="Max Turns"
139+
min={1}
140+
max={50}
141+
step={1}
142+
/>
98143
<div className="flex flex-col gap-2 w-full">
99144
<div className="flex items-center justify-between gap-2 w-full">
100145
<span className="text-sm font-medium">Tools</span>

frontend/src/components/flow/config/initializer.tsx

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,6 @@ export const InitializerConfig = ({ nodeId, data }: any) => {
2424
label="Sample Message (One per line)"
2525
placeholder="Enter sample messages, one per line."
2626
/>
27-
<GenericOption
28-
type="select"
29-
nodeId={nodeId}
30-
data={data}
31-
name="summary_method"
32-
label="Summary Method"
33-
options={[
34-
{ value: 'last_msg', label: 'Last Message' },
35-
{ value: 'reflection_with_llm', label: 'Reflection with LLM' },
36-
]}
37-
/>
38-
<GenericOption
39-
type="text"
40-
nodeId={nodeId}
41-
data={data}
42-
rows={3}
43-
name="summary_prompt"
44-
label="Summary Prompt"
45-
placeholder="Enter a prompt for the summary."
46-
/>
47-
<GenericOption
48-
type="range"
49-
nodeId={nodeId}
50-
data={data}
51-
name="max_turns"
52-
label="Max Turns"
53-
min={1}
54-
max={50}
55-
step={1}
56-
/>
5727
</div>
5828
</ScrollArea>
5929
);

frontend/src/components/flow/flow-canvas.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import { NodeButton } from './node-button';
2828
import { PythonViewer } from './python';
2929
import { useProject } from '@/hooks';
3030
import { debounce } from 'lodash-es';
31-
import { nanoid } from 'nanoid';
3231
import { Button } from '../ui/button';
3332
import { toast } from '@/hooks/use-toast';
33+
import { genId } from '@/lib/id';
3434

3535
const DEBOUNCE_DELAY = 500; // Adjust this value as needed
3636

@@ -329,7 +329,7 @@ export const FlowCanvas = ({
329329
});
330330

331331
const { offsetX, offsetY, width, height, ...cleanedData } = data;
332-
const newId = nanoid(8);
332+
const newId = genId();
333333
const newNode = {
334334
id: `${data.id}_${newId}`,
335335
type: data.id,
@@ -434,7 +434,7 @@ export const FlowCanvas = ({
434434
height?: number
435435
) => {
436436
setNodes((nds) => {
437-
const newId = nanoid(8);
437+
const newId = genId();
438438
const bounds = flowParent.current?.getBoundingClientRect();
439439
if (!bounds) return nds;
440440
const center = {
@@ -471,7 +471,7 @@ export const FlowCanvas = ({
471471

472472
setIsDirty(true);
473473
},
474-
[screenToFlowPosition, setNodes, nanoid]
474+
[screenToFlowPosition, setNodes]
475475
);
476476

477477
const onGeneratePython = async () => {

frontend/src/components/flow/node/assistant.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ export const AssistantNode: ComponentType<NodeProps> = ({
1919
data={data}
2020
selected={selected}
2121
type={type}
22-
ports={[
23-
{ type: 'target', name: '' },
24-
{ type: 'source', name: '' },
25-
]}
22+
ports={[{ type: 'target', name: '' }]}
2623
/>
2724
);
2825
};

frontend/src/hooks/use-chats.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useProjects } from './use-projects';
99
import { useTemplates } from './use-templates';
1010
import { createClient } from '@/lib/supabase/client';
1111
import { RealtimePostgresChangesPayload } from '@supabase/supabase-js';
12-
import { nanoid } from 'nanoid';
12+
import { genId } from '@/lib/id';
1313

1414
export function useChats() {
1515
const { data, error, mutate } = useSWR('/api/chats', fetcher);
@@ -198,7 +198,7 @@ export function useChat(chatId: number) {
198198
// Subscribe to chat status updates
199199
const supabase = createClient();
200200
const channel = supabase
201-
.channel(`chat_status_${nanoid(6)}`)
201+
.channel(`chat_status_${genId()}`)
202202
.on(
203203
'postgres_changes',
204204
{

frontend/src/lib/id.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
export const genId = (): number => {
2-
const timestamp = Math.floor(Date.now() / 1000); // Unix timestamp (seconds)
3-
const random = Math.floor(Math.random() * 100000); // 5-digit random number
4-
return timestamp * 100000 + random;
1+
import { customAlphabet } from "nanoid";
2+
3+
export const genId = (): string => {
4+
// Create custom nanoid without hyphens
5+
const nanoid = customAlphabet('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 8);
6+
return nanoid(6);
57
};

frontend/src/lib/supabase/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createBrowserClient } from '@supabase/ssr';
22
import { SupabaseClient } from '@supabase/supabase-js';
3-
import { nanoid } from 'nanoid';
3+
import { genId } from '../id';
44

55
export function createClient() {
66
return createBrowserClient(
@@ -61,7 +61,7 @@ export async function uploadFile(
6161
);
6262
}
6363

64-
const path = `${nanoid()}.${ext}`;
64+
const path = `${genId()}.${ext}`;
6565

6666
try {
6767
const { data, error } = await supabase.storage

0 commit comments

Comments
 (0)