When to Use Custom Code
Use custom code when:- A tool needs to call multiple APIs before returning a single response to the agent
- You need to transform, filter, or enrich data before the agent sees it
- Business rules, validation, or authorization logic should run server-side
- The integration requires custom authentication flows or token management
- You want to abstract complex backend systems behind a simple interface for the agent
How It Works
- You build an endpoint on your server that accepts requests from Simple AI
- You create an HTTP tool on your agent that points to your endpoint
- During a call, the agent calls your endpoint like any other tool
- Your server runs whatever logic you need — database queries, multi-API orchestration, business rules
- Your server returns a clean JSON response that the agent uses to continue the conversation
Example: Combined Customer Lookup
Instead of giving the agent three separate tools (CRM lookup, billing check, ticket search), build one endpoint that combines all three:Example: Eligibility Check with Business Rules
An insurance agent needs to check whether a caller is eligible for a specific plan. The rules are complex and change frequently, so they live in your backend:Example: Order Action with Side Effects
A support agent needs to process a return. This involves multiple steps that should happen atomically on your backend:Building Your Endpoint
Request Format
When the agent calls your tool, Simple AI sends a POST request with:- Headers — whatever you configured on the HTTP tool (typically an auth token)
- Body — JSON with the parameters the agent filled in based on the conversation
Response Format
Return a JSON object with the data the agent should communicate. Keep it concise — only include fields the agent will actually say out loud or use to make decisions.Error Handling
If your endpoint returns an error (4xx, 5xx) or times out, the agent handles it gracefully and continues the conversation. Return clear error messages when possible so the agent can tell the caller what went wrong:Best Practices
- Keep responses concise — the agent reads the response and communicates it to the caller. Large payloads with irrelevant fields slow everything down.
- Use descriptive tool descriptions — the agent decides when to call your tool based on its description. Be specific about the trigger conditions.
- Handle errors clearly — return human-readable error messages so the agent can explain the problem to the caller instead of saying “something went wrong.”
- Secure your endpoints — use authentication headers and validate them on your server. Your endpoint will receive call data that may include sensitive information.
- Log requests — log incoming requests and outgoing responses so you can debug issues and audit what happened during calls.
- Scope to the right nodes — in flow-based agents, assign your custom code tools only to the nodes where they are relevant.