diff --git a/cmd/lk/debugger_agent.go b/cmd/lk/debugger_agent.go index 7df2bed8..f83b72c1 100644 --- a/cmd/lk/debugger_agent.go +++ b/cmd/lk/debugger_agent.go @@ -54,6 +54,7 @@ type agentSession struct { speak speakFunc // nil in text mode replyWait time.Duration + settle time.Duration mic micStream speaker playout @@ -82,6 +83,7 @@ func newAgentSession(conn net.Conn, reader io.Reader, speak speakFunc) *agentSes reader: reader, speak: speak, replyWait: defaultReplyWait, + settle: turnSettle, pending: make(map[string]chan *agent.SessionResponse), subs: make(map[*eventSub]struct{}), observers: make(map[*eventSub]struct{}), @@ -680,7 +682,7 @@ speaking: // Output while the user was still being heard (the tail of an earlier // reply) does not answer this turn, so the turn waits for the agent to // transcribe the speech and respond to it. - s.awaitQuiet(ctx, sub, s.replyWait, turnSettle, nil, deliver, func() bool { return responded }) + s.awaitQuiet(ctx, sub, s.replyWait, s.settle, nil, deliver, func() bool { return responded }) // A handoff target usually introduces itself from on_enter, which can // start after the previous agent went quiet. Hold the turn open briefly so // that introduction reads as part of the handoff. diff --git a/cmd/lk/debugger_agent_test.go b/cmd/lk/debugger_agent_test.go index bc15818f..d2a7f26b 100644 --- a/cmd/lk/debugger_agent_test.go +++ b/cmd/lk/debugger_agent_test.go @@ -102,6 +102,9 @@ func newFakeAgentMode(t *testing.T, audio bool) (*fakeAgent, *agentSession) { speak = nil } sess := newAgentSession(server, nil, speak) + // The fake agent never pauses mid-reply, so it needs no settle long + // enough to outlast a delegating model's pause. + sess.settle = 100 * time.Millisecond t.Cleanup(func() { client.Close(); server.Close() }) return fa, sess } @@ -631,7 +634,7 @@ func TestAudioSayWaitsForTheAgentToHearTheUser(t *testing.T) { fa.sendState(agent.AgentState_AS_SPEAKING) fa.sendAssistant("June tenth has already passed.") fa.sendState(agent.AgentState_AS_LISTENING) - time.Sleep(turnSettle + 500*time.Millisecond) + time.Sleep(sess.settle + 200*time.Millisecond) select { case <-run.done: t.Fatal("the turn ended before the agent heard the user") @@ -734,6 +737,9 @@ func TestAudioSayWaitsForHandoffIntroduction(t *testing.T) { fa.nextSpoken() fa.sendUser("billing please") fa.sendState(agent.AgentState_AS_THINKING) + // The old agent answers before handing off, so the turn has its reply and + // only the handoff wait can hold it open for the introduction. + fa.sendAssistant("Transferring you to billing.") old := "assistant" fa.sendEvent(&agent.AgentSessionEvent{Event: &agent.AgentSessionEvent_ConversationItemAdded_{ ConversationItemAdded: &agent.AgentSessionEvent_ConversationItemAdded{Item: &agent.ChatContext_ChatItem{ @@ -742,11 +748,12 @@ func TestAudioSayWaitsForHandoffIntroduction(t *testing.T) { }}) // The old agent goes quiet before the new one has introduced itself. fa.sendState(agent.AgentState_AS_LISTENING) - time.Sleep(turnSettle + 500*time.Millisecond) + time.Sleep(sess.settle + 200*time.Millisecond) fa.sendAssistant("Hi, billing here.") run.wait(t) - require.Len(t, run.got, 3) - require.Equal(t, "handoff", run.got[1].Type) - require.Equal(t, "Hi, billing here.", run.got[2].Text) + require.Len(t, run.got, 4) + require.Equal(t, "handoff", run.got[2].Type) + require.Equal(t, "Hi, billing here.", run.got[3].Text) + require.Equal(t, "Transferring you to billing.\nHi, billing here.", run.res.Reply) }