From aaebfbb24ffa0b7b6358a725d7dd39273fa39e50 Mon Sep 17 00:00:00 2001 From: Ivan Sekovanikj Date: Thu, 19 Nov 2026 14:32:43 +0100 Subject: [PATCH] fix(examples): crew approvals come back in a reopened app The tools that ask first are declared with the server executor, as the SDK docs say, so their question is on the reply's step, with a line from the call, and the card above the composer that repeated it is gone. AI-3392 --- .../crew_assistant/app/agent/crewTools.ts | 4 +- .../crew_assistant/app/agent/deviceTools.ts | 5 +- .../app/screens/AgentNotices.tsx | 58 ++----------------- 3 files changed, 12 insertions(+), 55 deletions(-) diff --git a/examples/voice_agents/crew_assistant/app/agent/crewTools.ts b/examples/voice_agents/crew_assistant/app/agent/crewTools.ts index 05ad0714d..22ea70760 100644 --- a/examples/voice_agents/crew_assistant/app/agent/crewTools.ts +++ b/examples/voice_agents/crew_assistant/app/agent/crewTools.ts @@ -155,15 +155,17 @@ export const DISPLAY_TITLES: Record = { /** What the person is asked before a call runs, by tool. */ export const APPROVALS: Record = { - book_check_in: { allowTitle: 'Book it', title: 'Book this check-in?' }, + book_check_in: { allowTitle: 'Book it', reasonArgument: 'topic', title: 'Book this check-in?' }, create_support_ticket: { allowTitle: 'Send for review', message: 'The owner approves it before it goes to repairs, and you hear back here.', + reasonArgument: 'summary', title: 'Draft this repair ticket?', }, request_shift_swap: { allowTitle: 'Send request', message: 'Your teammate and the shift leader see it.', + reasonArgument: 'note', title: 'Ask a teammate to take your shift?', }, }; diff --git a/examples/voice_agents/crew_assistant/app/agent/deviceTools.ts b/examples/voice_agents/crew_assistant/app/agent/deviceTools.ts index 25cb559e9..b66830a89 100644 --- a/examples/voice_agents/crew_assistant/app/agent/deviceTools.ts +++ b/examples/voice_agents/crew_assistant/app/agent/deviceTools.ts @@ -81,7 +81,10 @@ export const createDeviceTools = ({ clientId, userId }: { clientId: string; user ...(APPROVALS[name] ? { timeoutMs: APPROVAL_TIMEOUT_MS } : {}), description, displayTitle: DISPLAY_TITLES[name], - executor: 'client', + // A tool that asks first is declared as the server's, so the router asks on the reply's + // step, where an app reopened while the call waits finds the question. It asks a client + // tool's question there only once it can address this phone, which the SDK can't name yet. + executor: APPROVALS[name] ? 'server' : 'client', name, parameters, run: async (input, call) => { diff --git a/examples/voice_agents/crew_assistant/app/screens/AgentNotices.tsx b/examples/voice_agents/crew_assistant/app/screens/AgentNotices.tsx index f95b2787e..6bf8bf0cf 100644 --- a/examples/voice_agents/crew_assistant/app/screens/AgentNotices.tsx +++ b/examples/voice_agents/crew_assistant/app/screens/AgentNotices.tsx @@ -1,30 +1,14 @@ import { useSyncExternalStore } from 'react'; -import { Pressable, StyleSheet, Text, View } from 'react-native'; +import { Pressable, StyleSheet, Text } from 'react-native'; -import type { Session, ToolApprovalRequest } from '@stream-io/stream-agents'; +import type { Session } from '@stream-io/stream-agents'; import { useStateStore } from 'stream-chat-expo'; -import { AIToolApprovalCard } from 'stream-chat-expo/ai-components'; import { type Chat, type ChatState, chatStore } from '../agent/conversation'; import { useAppContext } from '../contexts/AppContext'; -const NONE: readonly ToolApprovalRequest[] = []; - const sessionSelector = ({ session }: ChatState) => ({ session }); -// What the call would do, in a line, from the arguments the model wrote. -const detailsOf = ({ arguments: written }: ToolApprovalRequest) => { - try { - const parsed = JSON.parse(written) as Record; - return Object.entries(parsed) - .filter(([, value]) => typeof value === 'string' || typeof value === 'number') - .map(([key, value]) => `${key.replace(/_/g, ' ')}: ${String(value)}`) - .join(' ยท '); - } catch { - return undefined; - } -}; - const Failure = ({ session }: { session: Session }) => { const { retry } = useAppContext(); const failure = useSyncExternalStore( @@ -40,48 +24,16 @@ const Failure = ({ session }: { session: Session }) => { ); }; -const Requests = ({ session }: { session: Session }) => { - const approvals = useSyncExternalStore( - session.conversation.subscribe, - () => session.conversation.get().approvals ?? NONE, - ); - if (approvals.length === 0) return null; - return ( - - {approvals.map((request) => ( - session.decide(request.id, { allowed })} - /> - ))} - - ); -}; - /** - * What the open conversation's session needs the person for, above the composer: why the agent - * couldn't answer, with a way to ask again, and the calls of the phone's tools that ask first. The - * phone asks through `responses.create`, so those wait on its session rather than on the reply's - * step, and the person answers them here. + * Why the open conversation's agent couldn't answer, above the composer, with a way to ask again. + * A call that asks first is asked on its step in the conversation, with the approver. */ export const AgentNotices = ({ chat }: { chat: Chat }) => { const { session } = useStateStore(chatStore(chat), sessionSelector); - return session ? ( - <> - - - - ) : null; + return session ? : null; }; const styles = StyleSheet.create({ - container: { gap: 8, paddingBottom: 8, paddingHorizontal: 16 }, failure: { alignItems: 'center', paddingBottom: 8 }, failureText: { color: '#B00020', fontSize: 14 }, retryText: { color: '#C8102E', fontSize: 15, fontWeight: '700', paddingTop: 2 },