Appearance
HTTP tools
An HTTPTool block is one HTTP endpoint the agent can call. List it on the Agent block under http:. The tool is registered when the agent is built, the same way as a tool on tools:.
http: works on a normal agent, an agent used as a tool, a graph node, and a workflow step. The same named block can be listed from more than one agent.
Call agent.cleanup() when you are done. It closes the HTTP clients the loader created.
Installation
HTTP tools need elsai-yaml 0.4.1 or later and elsai-agents 0.4.1 or later (elsai.tools.http).
bash
pip install --upgrade --extra-index-url https://elsai-agents.elsai.ai/root/ "elsai-agents==0.4.4"
pip install --upgrade --extra-index-url https://elsai-agents.elsai.ai/root/ "elsai-yaml==0.4.3"
pip install --extra-index-url https://core-packages.elsai.ai/root/elsai-model/ "elsai-model[openai]==2.1.5"Each example below is its own file. This page uses the JSONPlaceholder sample API. It returns JSON and does not need an API key. It does not save POST, PUT, PATCH, or DELETE.
http: must be a list. Write a block list, or a quoted flow list such as http: ["${list_comments}"]. Each named HTTPTool block may appear once on an agent. An inline map is the same fields without a name.
Omit send and POST, PUT, and PATCH send a JSON body. GET and DELETE send query parameters. Set send: body or send: query to choose. parameters is a map of names to JSON Schema objects. required lists names that must be present. defaults fills a parameter when the model omits it.
GET
This example uses the JSONPlaceholder sample API. postId is sent as a query parameter to https://jsonplaceholder.typicode.com/comments.
get.yaml:
yaml
openai:
type: OpenAIModel
model_id: "{{$OPENAI_MODEL:gpt-4o-mini}}"
list_comments:
type: HTTPTool
name: list_comments
description: List comments for a blog post. Pass the numeric postId.
endpoint: https://jsonplaceholder.typicode.com/comments
method: GET
parameters:
postId:
type: integer
description: Blog post id.
required: [postId]
comments_agent:
type: Agent
name: comments_agent
system_prompt: Call list_comments, then answer from its result.
model: ${openai}
http:
- ${list_comments}python
from elsai.config import yaml_to_agent
agent = yaml_to_agent("get.yaml", entry="comments_agent")
try:
print(agent("What is the email on the first comment for post 1?"))
finally:
agent.cleanup()POST
This example uses the JSONPlaceholder sample API. title, body, and userId are sent as JSON to https://jsonplaceholder.typicode.com/posts.
post.yaml:
yaml
openai:
type: OpenAIModel
model_id: "{{$OPENAI_MODEL:gpt-4o-mini}}"
create_post:
type: HTTPTool
name: create_post
description: Create a blog post.
endpoint: https://jsonplaceholder.typicode.com/posts
method: POST
parameters:
title:
type: string
description: Post title.
body:
type: string
description: Post body.
userId:
type: integer
description: Author id.
required: [title, body, userId]
writer:
type: Agent
name: writer
system_prompt: Call create_post, then answer from its result.
model: ${openai}
http:
- ${create_post}python
from elsai.config import yaml_to_agent
agent = yaml_to_agent("post.yaml", entry="writer")
try:
print(agent("Create a post titled HTTP tool with body Sent from YAML and userId 1."))
finally:
agent.cleanup()PUT
This example uses the JSONPlaceholder sample API. title, body, and userId are sent as JSON to https://jsonplaceholder.typicode.com/posts/1, which replaces that post.
put.yaml:
yaml
openai:
type: OpenAIModel
model_id: "{{$OPENAI_MODEL:gpt-4o-mini}}"
update_post:
type: HTTPTool
name: update_post
description: Replace blog post 1.
endpoint: https://jsonplaceholder.typicode.com/posts/1
method: PUT
parameters:
title:
type: string
description: Post title.
body:
type: string
description: Post body.
userId:
type: integer
description: Author id.
required: [title, body, userId]
editor:
type: Agent
name: editor
system_prompt: Call update_post, then answer from its result.
model: ${openai}
http:
- ${update_post}python
from elsai.config import yaml_to_agent
agent = yaml_to_agent("put.yaml", entry="editor")
try:
print(agent("Replace post 1 with title Updated, body Replaced, and userId 1."))
finally:
agent.cleanup()PATCH
This example uses the JSONPlaceholder sample API. title is sent as JSON to https://jsonplaceholder.typicode.com/posts/1.
patch.yaml:
yaml
openai:
type: OpenAIModel
model_id: "{{$OPENAI_MODEL:gpt-4o-mini}}"
patch_post:
type: HTTPTool
name: patch_post
description: Change the title of blog post 1.
endpoint: https://jsonplaceholder.typicode.com/posts/1
method: PATCH
parameters:
title:
type: string
description: New title.
required: [title]
editor:
type: Agent
name: editor
system_prompt: Call patch_post, then answer from its result.
model: ${openai}
http:
- ${patch_post}python
from elsai.config import yaml_to_agent
agent = yaml_to_agent("patch.yaml", entry="editor")
try:
print(agent("Change the title of post 1 to Patched."))
finally:
agent.cleanup()DELETE
This example uses the JSONPlaceholder sample API. The call goes to https://jsonplaceholder.typicode.com/posts/1 with no parameters.
delete.yaml:
yaml
openai:
type: OpenAIModel
model_id: "{{$OPENAI_MODEL:gpt-4o-mini}}"
delete_post:
type: HTTPTool
name: delete_post
description: Delete blog post 1.
endpoint: https://jsonplaceholder.typicode.com/posts/1
method: DELETE
editor:
type: Agent
name: editor
system_prompt: Call delete_post, then answer from its result.
model: ${openai}
http:
- ${delete_post}python
from elsai.config import yaml_to_agent
agent = yaml_to_agent("delete.yaml", entry="editor")
try:
print(agent("Delete post 1."))
finally:
agent.cleanup()Credentials
This example uses the httpbin sample API. https://httpbin.org/get echoes the request, including the header, so you can see where the token went. Put the token in the environment and read it with {{$ENV_VAR:}}. The file does not take a live HTTP client.
yaml
header_lookup:
type: HTTPTool
name: header_lookup
description: Look up a member and send a bearer token.
endpoint: https://httpbin.org/get
method: GET
parameters:
member_id:
type: string
description: Member identifier.
required: [member_id]
credential: "{{$HTTP_DEMO_TOKEN:}}"
credential_in: header
credential_name: Authorization
credential_template: "Bearer {}"{} in credential_template is replaced with the credential value. That template is for a header. credential_in is header, query, or body. Set credential_name to the header, query parameter, or body field that carries the value.
headers is a map of strings for headers that are not the credential. A credential replaces a header of the same name.
One tool without an agent
yaml_to_http builds the tool and does not build an agent. Pass it to Agent yourself, and close it yourself. agent.cleanup() only closes clients the loader attached.
python
from elsai.config import yaml_to_http
list_comments = yaml_to_http("get.yaml", entry="list_comments")Fields
| Key | Required | Meaning |
|---|---|---|
name | yes | Tool name. Letters, digits, _, -, at most 64 characters |
description | yes | What the model reads |
endpoint | yes | Absolute http or https URL |
method | yes | GET, POST, PUT, PATCH, or DELETE |
parameters | Map of parameter name to a JSON Schema object | |
required | Parameter names that must be sent | |
defaults | Values used when the model omits a parameter | |
headers | Static headers. String map | |
send | body or query. See GET | |
timeout_seconds | Positive number. Default 30 | |
credential | Secret value. Use {{$ENV_VAR:}} | |
credential_in | header, query, or body | |
credential_name | Header, query, or body field that carries the credential | |
credential_template | Header template. {} is the credential value | |
output_schema | JSON Schema stored on the tool. The response is not checked against it |
Common mistakes
| Problem | What to do |
|---|---|
Building HTTPTool requires elsai-agents 0.4.1+ | Install elsai-agents 0.4.1 or later |
http: [${list_comments}] parse error | Quote it, http: ["${list_comments}"], or use a block list |
The same ${block} twice on one agent | List that tool once |
| Token written in the file | Use credential: "{{$TOKEN:}}" |
client on the block | The loader creates the HTTP client. Close it with agent.cleanup() |
| Unknown key | Stay on the fields in the table above |