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 91dce23 commit 7a335b6
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 @@ -38,6 +38,9 @@ export const HeaderChatButton: React.FC<HeaderChatButtonProps> = (props) => {
const [traceId, setTraceId] = useState<string | undefined>(undefined);
const [chatSize, setChatSize] = useState<number | 'fullscreen' | 'dock-right'>('dock-right');
const flyoutFullScreen = chatSize === 'fullscreen';
const [rootAgentId, setRootAgentId] = useState<string>(
new URL(window.location.href).searchParams.get('agent_id') || ''
);

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

Expand Down Expand Up @@ -73,6 +76,7 @@ export const HeaderChatButton: React.FC<HeaderChatButtonProps> = (props) => {
setTitle,
traceId,
setTraceId,
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 @@ -25,6 +25,7 @@ export interface IChatContext {
setTitle: React.Dispatch<React.SetStateAction<string | undefined>>;
traceId?: string;
setTraceId: React.Dispatch<React.SetStateAction<string | undefined>>;
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 @@ -36,6 +36,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 @@ -23,6 +23,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 @@ -31,7 +31,7 @@ export class OllyChatService implements ChatService {
messages: IMessage[];
memoryId: string;
}> {
const { input, sessionId } = payload;
const { input, sessionId, rootAgentId } = request.body;
const opensearchClient = context.core.opensearch.client.asCurrentUser;

if (payload.sessionId) {
Expand All @@ -57,7 +57,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 7a335b6

Please sign in to comment.