Human as Tool
Create LLM-callable tools that contact humans for input
- The Basic Usage method is the easiest way to create a human contact tool
- The Fetch Response method is useful if you want more control over the response handling
- The Creating / Fetching method gives you full control over the contact flow
- See Advanced Usage for concepts like response options and contact channels
Structure
Human contact tools are built on the Human Contact API.
Methods
There are three main jobs-to-be-done that you can control when using human contact tools:
- Creating the contact request
- Halting execution until the human responds
- Passing the response back to the LLM
In all cases, the HumanLayer SDK handles finding the right human and collecting their response.
Basic Usage
You can use the human_as_tool
method to create a tool that an LLM can use to contact a human.
The method returns a native python function that can be used as a tool in any LLM framework that supports inferring tool structure from the function signature, docstring, and type hints.
By default, the tool will use the default contact channel for the project associated with your HUMANLAYER_API_KEY.
You may want to give your LLM access to multiple humans as tools. This example uses a Slack Contact Channel, but you can use any of the Contact Channels supported by HumanLayer.
In this case, the HumanLayer SDK handles:
- Creating the contact request
- Halting execution until the human responds
- Passing the response back to the LLM
Example
See 04-human_as_tool_linkedin.py for a full example.
Fetch Response
You can use the fetch_human_response
method to halt execution until the human responds,
and receive a result that you can use to decide what to do next.
In this case, the HumanLayer SDK handles:
- Creating the contact request
- Halting execution until the human responds
And your code is responsible for:
- Handling the human’s response
Creating and Fetching
For maximum control over the contact flow, you can create and fetch responses separately. This is useful if you want to implement your own waiting logic or integrate with a custom event loop.
In this case, the HumanLayer SDK handles:
- Creating the contact request
- Fetching the response status
And your code is responsible for:
- Halting execution until the human responds
- Handling the response
Advanced Usage
Response Options
You can provide structured response options to guide the human’s response:
Contact Channels
HumanLayer supports multiple contact channels:
- Slack (
SlackContactChannel
) - Email (
EmailContactChannel
) - SMS (
SMSContactChannel
) - WhatsApp (
WhatsAppContactChannel
)
See Contact Channels for more details.