56 lines
1.7 KiB
Plaintext
56 lines
1.7 KiB
Plaintext
---
|
|
title: Using Tool Variables
|
|
slug: guides/agents/tool-variables
|
|
---
|
|
|
|
You can use **tool variables** to specify environment variables available to your custom tools.
|
|
For example, if you set a tool variable `PASSWORD` to `banana`, then write a custom function that prints `os.getenv('PASSWORD')` in the tool, the function will print `banana`.
|
|
|
|
## Assigning tool variables in the ADE
|
|
|
|
To assign tool variables in the Agent Development Environment (ADE), click on **Env Vars** to open the **Environment Variables** viewer:
|
|
|
|
<img src="../../images/env_vars_button.png" />
|
|
|
|
Once in the **Environment Variables** viewer, click **+** to add a new tool variable if one does not exist.
|
|
|
|
<img src="../../images/tool_variables.png" />
|
|
|
|
## Assigning tool variables in the API / SDK
|
|
|
|
You can also assign tool variables on agent creation in the API with the `tool_exec_environment_variables` parameter:
|
|
<CodeGroup>
|
|
```curl title="curl" {7-9}
|
|
curl -X POST http://localhost:8283/v1/agents/ \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"memory_blocks": [],
|
|
"llm":"openai/gpt-4o-mini",
|
|
"embedding":"openai/text-embedding-3-small",
|
|
"tool_exec_environment_variables": {
|
|
"API_KEY": "your-api-key-here"
|
|
}
|
|
}'
|
|
```
|
|
```python title="python" {5-7}
|
|
agent_state = client.agents.create(
|
|
memory_blocks=[],
|
|
model="openai/gpt-4o-mini",
|
|
embedding="openai/text-embedding-3-small",
|
|
tool_exec_environment_variables={
|
|
"API_KEY": "your-api-key-here"
|
|
}
|
|
)
|
|
```
|
|
```typescript title="node.js" {5-7}
|
|
const agentState = await client.agents.create({
|
|
memoryBlocks: [],
|
|
model: "openai/gpt-4o-mini",
|
|
embedding: "openai/text-embedding-3-small",
|
|
toolExecEnvironmentVariables: {
|
|
"API_KEY": "your-api-key-here"
|
|
}
|
|
});
|
|
```
|
|
</CodeGroup>
|