Skip to content

[Feature]: Support ask_user tool #7643

Description

Description

Feature request for an ask_user tool that an agent could use to ask clarifying questions to a user, as found in other harnesses. This could include suggested responses, or a schema that the user should reply with, for example. When the agent calls the tool, iteration would pause and the tool call would be returned to the client, allowing the user to then supply a response (similar to function approval).

Currently, something like this could be implemented manually using a declaration-only tool, but there is a potential issue that if the agent calls the tool at the same time as a different tool with an implementation, then all tool calls get returned to the client, and the client will have to execute the tool calls manually, not just the ask_user tool. It would be better if the other tool calls would remain pending, and get executed when when the iteration continues.

Code Sample

import asyncio
import random
from typing import Annotated

from agent_framework import Agent, FunctionTool
from agent_framework.foundry import FoundryChatClient
from azure.identity import AzureCliCredential
from pydantic import BaseModel, Field


class AskUserInput(BaseModel):
    question: Annotated[str, Field(description="The question to ask the user.")]
    options: Annotated[list[str] | None, Field(description="The options to present to the user.")] = None


ask_user = FunctionTool(
    name="ask_user",
    description="Ask the user a question.",
    input_model=AskUserInput,
)


def roll_dice() -> int:
    """Roll a six-sided dice."""
    return random.randint(1, 6)


async def main() -> None:
    client = FoundryChatClient(credential=AzureCliCredential())

    agent = Agent(
        client=client,
        name="Agent",
        instructions="You are a helpful agent. "
        "If the user asks something vague, ask them for clarification using the ask_user tool. "
        "If the user asks you to roll a dice, use the roll_dice tool.",
        tools=[ask_user, roll_dice],
    )

    result = await agent.run("I need help with something. Also, roll a dice for me.")

    for content in result.messages[0].contents:
        print(content.to_dict())


if __name__ == "__main__":
    asyncio.run(main())

Both function calls get returned to the user, meaning the roll_dice call needs to be executed manually by the user.

{'type': 'function_call', 'call_id': 'call_SumNAHKXnlhQijNoq39XkiQJ', 'name': 'ask_user', 'arguments': '{"question":"What would you like help with?","options":["Explain something","Write something","Debug something","Other"]}', 'user_input_request': True, 'id': 'call_SumNAHKXnlhQijNoq39XkiQJ', 'additional_properties': {'fc_id': 'fc_07bcf604e5c7017c006a7dcd59f68c8196855015c3fcf7a13a', 'status': 'completed'}}
{'type': 'function_call', 'call_id': 'call_zp1Np4C8fynjiNEJETvHCooT', 'name': 'roll_dice', 'arguments': '{}', 'user_input_request': True, 'id': 'call_zp1Np4C8fynjiNEJETvHCooT', 'additional_properties': {'fc_id': 'fc_07bcf604e5c7017c006a7dcd59f6a481969b81630d95c2ae22', 'status': 'completed'}}

Language/SDK

Both

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageUsage: [Issues], Target: All issues that still need to be triaged

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions