| import 'package:schemantic/schemantic.dart'; |
| |
| import '../../logic/run/agent_interaction_controller.dart'; |
| import '../../models/agent_pending_interaction.dart'; |
| import '../../models/agent_tool_event.dart'; |
| import '../../models/agent_tool_id.dart'; |
| import '../base/agent_tool.dart'; |
| import '../tool_schemas.dart'; |
| |
| class AskQuestionTool extends AgentTool<AskQuestionInput, AskQuestionOutput> { |
| const AskQuestionTool({ |
| required this.interactionController, |
| }); |
| |
| final AgentInteractionController interactionController; |
| |
| @override |
| AgentToolId get toolId => AgentToolId.askQuestion; |
| |
| @override |
| String get name => 'askQuestion'; |
| |
| @override |
| String get description => |
| 'Present a blocking multiple-choice question to the user to clarify requirements or get design decisions. ' |
| 'Must provide exactly three options, with the first being the recommended choice.'; |
| |
| @override |
| SchemanticType<AskQuestionInput> get inputSchema => AskQuestionInput.$schema; |
| |
| @override |
| SchemanticType<AskQuestionOutput> get outputSchema => AskQuestionOutput.$schema; |
| |
| @override |
| Future<AskQuestionOutput> run(AskQuestionInput input) async { |
| if (input.options.length != 3) { |
| return AskQuestionOutput( |
| success: false, |
| error: 'askQuestion requires exactly 3 options.', |
| ); |
| } |
| |
| final answer = await interactionController.askQuestion( |
| AgentQuestionRequest( |
| header: input.header.trim(), |
| question: input.question.trim(), |
| options: [ |
| for (final option in input.options) |
| AgentQuestionOption( |
| label: option.label.trim(), |
| description: option.description.trim(), |
| ), |
| ], |
| ), |
| ); |
| |
| return AskQuestionOutput(success: true, answer: answer); |
| } |
| |
| @override |
| AgentToolEvent mapToToolEvent(AskQuestionInput input, AskQuestionOutput output) { |
| return createToolEvent( |
| status: output.success ? ToolStatus.success : ToolStatus.error, |
| summary: output.success ? 'askQuestion - answered' : 'askQuestion - failed', |
| errorMessage: output.error, |
| ); |
| } |
| } |