Overseas access: www.kdjingpai.com
Bookmark Us
Current Position:fig. beginning " Course materials

12 - Factor Agents 1. Natural Language to Tool Calls

2025-07-22 45

One of the most common patterns when building intelligences is converting natural language into structured tool calls. This is a powerful pattern that allows you to build intelligences that can reason about tasks and execute them.

12 - Factor Agents 1. Natural Language to Tool Calling - 1

The pattern, when applied atomically, is to take a phrase (e.g.)

Can you create a $750 payment link for Terri to sponsor the AI tinkerers (AI enthusiasts) meetup in February?

into a structured object that describes the Stripe API call, as follows

{
"function": {
"name": "create_payment_link",
"parameters": {
"amount": 750,
"customer": "cust_128934ddasf9",
"product": "prod_8675309",
"price": "prc_09874329fds",
"quantity": 1,
"memo": "嗨 Jeff - 请查看下方为赞助二月份 ai tinkerers (AI 爱好者) 聚会而创建的支付链接"
}
}
}

take note of: In practice, the Stripe API is a bit more complex, with a Intelligence that actually performs this operation  will either build this load (payload) with the correct IDs by listing the customer, listing the product, listing the price, etc., or include those IDs in the prompt/context window (we'll see later that the two are somehow the same!). .

The deterministic code can then receive this payload and process it. (For more on this, see Element 3)

# 大语言模型接收自然语言并返回一个结构化对象
nextStep = await llm.determineNextStep(
"""
为 Jeff 创建一个 750 美元的支付链接
用于赞助二月份的 AI tinkerers (AI 爱好者) 聚会
"""
)
# 根据其功能处理结构化输出
if nextStep.function == 'create_payment_link':
stripe.paymentlinks.create(nextStep.parameters)
return  # 或者任何你想要的操作,见下文
elif nextStep.function == 'something_else':
# ... 更多情况
pass
else:  # 模型没有调用我们已知的工具
# 执行其他操作
pass

take note of: A full-fledged intelligence would take the result of the API call and loop through it, eventually returning something like the following

I have successfully created a payment link for Terri for $750 to sponsor the AI tinkerers (AI enthusiasts) gathering in February. Here is the link: https://buy.stripe.com/test_1234567890

nevertheless, we will actually skip that step here and leave it to be discussed in another element, which you can also choose whether or not you want to integrate (up to you!). .

Recommended

Can't find AI tools? Try here!

Just type in the keyword Accessibility Bing SearchYou can quickly find all the AI tools on this site.

inbox

Contact Us

Top

en_USEnglish