Skip to content

Commit

Permalink
feat: use the agent id from request body
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Nov 20, 2023
1 parent 53971bb commit 5eb1064
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions public/chat_header_button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export const HeaderChatButton: React.FC<HeaderChatButtonProps> = (props) => {
{}
);
const [selectedTabId, setSelectedTabId] = useState<TabId>('chat');
const [rootAgentId, setRootAgentId] = useState<string>(
new URL(window.location.href).searchParams.get('agent_id') || ''
);

if (!flyoutLoaded && flyoutVisible) flyoutLoaded = true;

Expand All @@ -61,6 +64,7 @@ export const HeaderChatButton: React.FC<HeaderChatButtonProps> = (props) => {
chatEnabled: props.chatEnabled,
contentRenderers: props.contentRenderers,
actionExecutors: props.actionExecutors,
rootAgentId,
}),
[
appId,
Expand Down
1 change: 1 addition & 0 deletions public/contexts/chat_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface IChatContext {
chatEnabled: boolean;
contentRenderers: Record<string, ContentRenderer>;
actionExecutors: Record<string, ActionExecutor>;
rootAgentId?: string;
}
export const ChatContext = React.createContext<IChatContext | null>(null);

Expand Down
1 change: 1 addition & 0 deletions public/hooks/use_chat_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const useChatActions = (): AssistantActions => {
// do not send abort signal to http client to allow LLM call run in background
body: JSON.stringify({
sessionId: chatContext.sessionId,
rootAgentId: chatContext.rootAgentId,
...(!chatContext.sessionId && { messages: chatState.messages }), // include all previous messages for new chats
input,
}),
Expand Down
1 change: 1 addition & 0 deletions server/routes/chat_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const llmRequestRoute = {
body: schema.object({
sessionId: schema.maybe(schema.string()),
messages: schema.maybe(schema.arrayOf(schema.any())),
rootAgentId: schema.string(),
input: schema.object({
type: schema.literal('input'),
context: schema.object({
Expand Down
4 changes: 2 additions & 2 deletions server/services/chat/olly_chat_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class OllyChatService implements ChatService {
messages: IMessage[];
memoryId: string;
}> {
const { input, sessionId } = request.body;
const { input, sessionId, rootAgentId } = request.body;
const opensearchClient = context.core.opensearch.client.asCurrentUser;

try {
Expand All @@ -51,7 +51,7 @@ export class OllyChatService implements ChatService {
}
const agentFrameworkResponse = (await opensearchClient.transport.request({
method: 'POST',
path: '/_plugins/_ml/agents/-jld3IsBXlmiPBu-5dDC/_execute',
path: `/_plugins/_ml/agents/${rootAgentId}/_execute`,
body: {
parameters: parametersPayload,
},
Expand Down

0 comments on commit 5eb1064

Please sign in to comment.