Files
baserow/web-frontend/modules/agent/components/AgentQuestionCard.vue
Davide Silvestri 638d7236c3 feat(agent): let triggered runs ask a person (#6812)
* feat(agent): let triggered runs ask a person

A trigger-started reply gets a built-in ask_person tool when the trigger's
may_ask_person is on (default). The call is held like an ask-first call:
the run pauses, counts as going for the overlap rule, and resumes with the
answer of someone who may approve tool calls, or is told nobody will
answer when the question is dismissed. Unattended replies are told that
nobody reads them and whether they may ask; follow-ups keep the
outside-data instruction. Later replies replay each decided question and
its answer as plain turns in their history.

* feat(agent): answer an agent's question in the conversation

A held ask_person call shows as its own card with an answer field, Send
answer and Dismiss, kept out of the approval card's batch actions. Only
people without the approve permission see it read-only. The trigger card
gets a switch to let the agent ask a person, and approval wording now
covers questions too.

* test(agent): cover asking a person end to end and record it in ADR 014

* refactor(agent): build the question tool like web fetch and tell it from actions

The question tool is a plain Pydantic AI tool in agent/tools.py that the
reply runner wraps in a FunctionToolset, like web fetch. A held call is a
question only when it has no tool key, so an action saved as ask_person
before the name was reserved keeps its normal approval. History prefetches
only the decided questions, and the pending approvals menu links to the
conversation only for a pending question.

* test(agent): cover Ask first in a triggered run end to end

With changes set to not ask first, a triggered run creates a database without waiting; turned back on, the same run waits for approval and finishes once approved.

* test(agent): open the Triggers section in the ask-a-person spec

The section was renamed on develop.

* fix(agent): keep web search off next to the question tool on older Gemini

Gemini before 3 refuses web search next to function tools. The question
tool now counts as one, so a triggered run that may ask a person no longer
sends both, gets a 400 and records a failed search on every run.

* fix(agent): keep the ask-a-person switch of a license-locked trigger read-only

The API refuses the change like the trigger's other locked settings, and
the card makes the section inert and the switch read-only, like the
overlap rule.

* fix(agent): reserve the web_fetch action name

An action named web_fetch on an agent with web fetch on gave two tools
with the same name, so every reply failed when its toolsets were built.

* refactor(agent): drop the special case for an action named ask_person

Agents are behind a flag with no production users, so the name is simply
reserved like the other built-in tools: a held ask_person call is always
a question, on the backend and in the conversation.

* fix(agent): answer a waiting question after asking is turned off

ask_person now defers its call, and the resumed run gets the answer, or
the dismissal note, as the call's result. Turning the trigger's switch off
only stops new questions, instead of telling the agent that an answered
question is no longer allowed while the card shows it as answered.

* fix(agent): decide calls held with a question from the pending approvals menu

The question shows as its link row to the conversation, and the other
held calls stay in a card below it, so they can still be approved or
rejected from the menu.
2026-11-25 17:17:04 +00:00

151 lines
4.5 KiB
Vue

<template>
<div
ref="card"
class="agent-question"
role="group"
tabindex="-1"
:aria-labelledby="titleId"
:aria-describedby="decided ? decisionId : undefined"
>
<div class="agent-question__header">
<i
class="iconoir-chat-bubble-question agent-question__icon"
aria-hidden="true"
/>
<span :id="titleId" class="agent-question__title">
{{ $t('agent.questionTitle', { name: agent.name }) }}
</span>
</div>
<div class="agent-question__body">
<p class="agent-question__question">{{ item.question }}</p>
<template v-if="!decided">
<p v-if="readOnly" class="agent-question__hint">
{{ $t('agent.questionReadOnly') }}
</p>
<template v-else>
<FormGroup
:label="$t('agent.questionAnswerLabel')"
small-label
required
>
<FormTextarea
v-model="answer"
auto-expandable
:min-rows="2"
:max-rows="10"
:maxlength="ASK_PERSON_ANSWER_MAX_LENGTH"
:placeholder="$t('agent.questionAnswerPlaceholder')"
:aria-label="$t('agent.questionAnswerLabel')"
:disabled="locked"
/>
</FormGroup>
<p :id="hintId" class="agent-question__hint">
{{ $t('agent.questionDismissHint') }}
</p>
<div class="agent-question__actions">
<Button
type="secondary"
size="small"
:disabled="locked"
:aria-describedby="hintId"
@click="dismiss"
>
{{ $t('agent.questionDismiss') }}
</Button>
<Button
type="primary"
size="small"
:disabled="locked || !trimmedAnswer"
@click="send"
>
{{ $t('agent.questionSend') }}
</Button>
</div>
</template>
</template>
<div v-else :id="decisionId">
<span
class="agent-question__decision"
:class="`agent-question__decision--${item.status}`"
>
<i
:class="answered ? 'iconoir-check-circle' : 'iconoir-prohibition'"
aria-hidden="true"
/>
{{
$t(answered ? 'agent.questionAnswered' : 'agent.questionDismissed')
}}
</span>
<p v-if="answered && item.answer" class="agent-question__answer">
{{ item.answer }}
</p>
</div>
</div>
</div>
</template>
<script setup>
import { computed, inject, ref, useId, watch } from 'vue'
import { APPROVAL_STATUS } from '@baserow/modules/agent/utils/replies'
import { ASK_PERSON_ANSWER_MAX_LENGTH } from '@baserow/modules/agent/constants'
/** A question a triggered run asks, for a person to answer or dismiss. */
const props = defineProps({
/** `{id, status, question, answer}`. */
item: { type: Object, required: true },
/** The viewer lacks the permission to decide, so only reads the question. */
readOnly: { type: Boolean, default: false },
/** The viewer may not decide right now, for example while the agent loads. */
disabled: { type: Boolean, default: false },
/** A decision about this question is being saved. */
deciding: { type: Boolean, default: false },
})
const emit = defineEmits(['decide'])
const agent = inject('agentApplication')
const titleId = useId()
const hintId = useId()
const decisionId = useId()
const card = ref(null)
const answer = ref('')
let submitted = false
const locked = computed(() => props.disabled || props.deciding)
const trimmedAnswer = computed(() => answer.value.trim())
const decided = computed(() => props.item.status !== APPROVAL_STATUS.PENDING)
const answered = computed(() => props.item.status === APPROVAL_STATUS.APPROVED)
function decide(decision) {
if (locked.value) return
submitted = true
emit('decide', [{ id: props.item.id, ...decision }])
}
function send() {
if (trimmedAnswer.value) {
decide({ approved: true, answer: trimmedAnswer.value })
}
}
function dismiss() {
decide({ approved: false })
}
// The answered card drops its buttons, so focus would otherwise fall to the page.
watch(
() => props.deciding,
(deciding) => {
if (deciding || !submitted) return
submitted = false
const active = document.activeElement
if (
decided.value &&
(!active || active === document.body || card.value.contains(active))
) {
card.value.focus()
}
},
{ flush: 'post' }
)
</script>