> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 需要用户输入

> 此示例演示了如何在代理执行过程中收集用户输入，允许用户提供工具参数的特定信息。

## 代码

```python cookbook/agent_concepts/user_control_flows/user_input_required.py theme={null}
from typing import List

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools import tool
from agno.tools.function import UserInputField
from agno.utils import pprint

# 您可以指定 user_input_fields，或留空以允许用户提供所有字段
@tool(requires_user_input=True, user_input_fields=["to_address"])
def send_email(subject: str, body: str, to_address: str) -> str:
    """
    发送电子邮件。

    Args:
        subject (str): 电子邮件的主题。
        body (str): 电子邮件的正文。
        to_address (str): 要发送电子邮件的地址。
    """
    return f"已发送邮件到 {to_address}，主题为 {subject}，正文为 {body}"

agent = Agent(
    model=OpenAIChat(id="gpt-4o-mini"),
    tools=[send_email],
    markdown=True,
)

agent.run("Send an email with the subject 'Hello' and the body 'Hello, world!'")
if agent.is_paused:
    for tool in agent.run_response.tools_requiring_user_input:
        input_schema: List[UserInputField] = tool.user_input_schema

        for field in input_schema:
            # 向用户显示字段信息
            print(f"\n字段: {field.name}")
            print(f"描述: {field.description}")
            print(f"类型: {field.field_type}")

            # 获取用户输入
            if field.value is None:
                user_value = input(f"请输入字段 {field.name} 的值: ")
                # 更新字段值
                field.value = user_value
            else:
                print(f"值: {field.value}")

    run_response = agent.continue_run()
    pprint.pprint_run_response(run_response)
```

## 用法

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="设置您的 API 密钥">
    ```bash theme={null}
    export OPENAI_API_KEY=xxx
    ```
  </Step>

  <Step title="安装库">
    ```bash theme={null}
    pip install -U agno openai
    ```
  </Step>

  <Step title="运行示例">
    <CodeGroup>
      ```bash Mac theme={null}
      python cookbook/agent_concepts/user_control_flows/user_input_required.py
      ```

      ```bash Windows theme={null}
      python cookbook/agent_concepts/user_control_flows/user_input_required.py
      ```
    </CodeGroup>
  </Step>
</Steps>

## 主要功能

* 使用 `@tool(requires_user_input=True)` 标记需要用户输入的工具
* 可以使用 `user_input_fields` 指定需要用户输入的字段
* 实现动态表单式界面以收集用户输入
* 处理用户提供和代理提供的值

## 用例

* 收集操作所需的参数
