Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/lk/debugger_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type agentSession struct {

speak speakFunc // nil in text mode
replyWait time.Duration
settle time.Duration
mic micStream
speaker playout

Expand Down Expand Up @@ -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{}),
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 12 additions & 5 deletions cmd/lk/debugger_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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{
Expand All @@ -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)
}
Loading