# Platform Functions

Platform functions are the universal tool primitive for agent data access. You register a SQL query, Python function, or AI composition, and agents can call it during conversations. No container, no deployment pipeline. The function runs on the platform's compute layer and returns results directly to the agent.

{% hint style="info" %}
**Conceptual overview.** For background on function types, built-in functions, and how functions relate to Actions and Skills, see the [Platform Functions conceptual docs](https://docs.amigo.ai/agent/platform-functions).
{% endhint %}

## Function Types

| Type                 | Description                                                            |
| -------------------- | ---------------------------------------------------------------------- |
| **SQL Table**        | Parameterized query returning rows across live and analytical data     |
| **SQL Scalar**       | Query returning a single computed value                                |
| **Python UDF**       | Custom Python logic on the compute layer                               |
| **AI Built-in**      | Composed AI operations (classify, summarize, extract, mask, sentiment) |
| **Foundation Model** | Foundation model call with patient context for complex reasoning       |

## Three Tool Categories

Every platform function surfaces as a tool in the agent's context graph. The agent sees a tool name, description, input schema, and result.

### Named Functions

Pre-registered functions with fixed input schemas. The agent calls them by name. All named function tool IDs use the `fn_` prefix (e.g., `fn_caller_history`, `fn_entity_confidence`).

The platform ships with built-in functions covering entity confidence assessment, caller history, patient summaries, intent classification, clinical extraction, PII redaction, care plan generation, handoff summaries, urgency assessment, and memory access. See the [conceptual docs](https://docs.amigo.ai/agent/platform-functions#built-in-functions) for the full list.

### Open Query (`fn_query`)

The agent writes read-only SQL at runtime for questions no named function anticipated. Queries are validated (SELECT/WITH only, DML rejected, row count capped) and run within workspace isolation.

### Open Write (`fn_write`)

The agent records new observations as world model events when no specific write tool exists. Follows the same confidence and write-scope rules as all other world model writes.

## Catalog Discovery

Functions can be auto-discovered from the compute catalog. Any function with a description becomes an agent tool automatically at session initialization. Three sources are merged by priority:

1. **Catalog discovery** - functions found with descriptions (lowest priority)
2. **Built-in defaults** - platform built-in functions with curated schemas
3. **Workspace-registered** - functions explicitly registered through the API (highest priority)

Higher-priority sources override lower ones by name.

## Context Graph Integration

Functions are available through `tool_call_specs` on context graph states. If a function is not in the current state's spec, the agent cannot see or call it.

```yaml
tool_call_specs:
  - tool_id: fn_entity_confidence
  - tool_id: fn_query
    additional_instruction: "Query world model data when no existing tool fits"
```

## Management Endpoints

All endpoints are workspace-scoped under `/v1/{workspace_id}/functions`.

| Operation    | Description                                                           |
| ------------ | --------------------------------------------------------------------- |
| **List**     | All registered functions for the workspace                            |
| **Register** | Add a function (must already exist in the compute catalog)            |
| **Delete**   | Remove the workspace registration (underlying function unaffected)    |
| **Test**     | Execute with sample input, returns result with timing                 |
| **Discover** | Query the catalog for available functions with descriptions           |
| **Sync**     | Auto-register all discovered catalog functions not already registered |
| **Query**    | Execute an open-scope read-only SQL query                             |

## CLI

Platform functions can be managed through Agent Forge:

```
forge platform function list       # List registered functions
forge platform function register   # Register a new function
forge platform function test       # Test with sample input
forge platform function delete     # Remove registration
forge platform function query      # Run an open SQL query
forge platform function catalog    # Discover available functions
forge platform function sync       # Auto-register all discovered functions
```

## Migration from Data-MCP

Platform functions replace [Data-MCP](https://docs.amigo.ai/developer-guide/platform-api/platform-api/data-mcp) for agent data access. The key differences:

|                      | Data-MCP                     | Platform Functions                      |
| -------------------- | ---------------------------- | --------------------------------------- |
| **Integration**      | External MCP client required | Built into the agent reasoning pipeline |
| **Access**           | SQL queries only             | SQL + Python + AI operations            |
| **Tool resolution**  | Separate from context graph  | State-gated through `tool_call_specs`   |
| **Write capability** | Read-only                    | Read + write (via `fn_write`)           |
| **Discovery**        | Manual                       | Auto-discovery from compute catalog     |

Data-MCP remains available during the transition. New integrations should use platform functions.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.amigo.ai/developer-guide/platform-api/platform-api/platform-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
