api_registry_workflow.mdā¢10.1 kB
# API Registry Workflow - API-Level Architecture
## šÆ KEY CONCEPT: Register API Once, Call Any Path
```
Register: github_api (host + base_path)
Call: /repos/databricks/mlflow
Call: /user/repos
Call: /orgs/databricks/members
= 1 registration, infinite paths
```
---
## š“ TOOL CALL SEQUENCE VALIDATOR
**Before making ANY tool call, check this:**
| Tool | Must Call First | Action if NO |
|------|----------------|--------------|
| `execute_api_call` | `check_api_http_registry` | **STOP! Check registry first!** |
| `register_api` | `fetch_api_documentation` | **STOP! Fetch docs first!** |
---
## šØ MANDATORY WORKFLOW
```
User asks for API data
ā
Q1: Did I call check_api_http_registry in THIS turn?
NO ā STOP! Call it NOW
YES ā Continue
ā
Q2: Is API registered? (check by api_name like "github_api")
YES ā execute_api_call(api_name="github_api", path="/repos/...")
NO ā Need to register
ā
Q3: Did I call fetch_api_documentation in THIS turn?
NO ā STOP! Call it NOW
YES ā register_api(api_name="github_api", host="...", ...)
Then check registry again!
```
---
## šØ CRITICAL RULES
### RULE 1: Register API (not endpoint)
```
ā WRONG: Register "fred_series" and "fred_category" separately
ā
RIGHT: Register "fred_api" ONCE, call any path
```
### RULE 2: Check registry AND available_endpoints before every call
```
Before execute_api_call:
ā” Did I call check_api_http_registry in THIS turn?
ā” Am I using api_name from the registry response?
ā” Did I check the 'available_endpoints_parsed' field?
ā” Is the path I'm using listed in '_endpoint_paths'?
If NO to ANY ā STOP! That's hallucination!
MANDATORY: check_api_http_registry returns 'available_endpoints_parsed'
with documented paths. DO NOT call paths that aren't listed!
```
### RULE 3: Always fetch docs before registering
```
Before register_api:
ā” Did I call fetch_api_documentation in THIS turn?
ā” Am I using host/base_path/auth_type from docs response?
If NO to either ā STOP! Fetch docs first!
```
### RULE 4: Handle API errors intelligently
```
If execute_api_call returns 404 (Not Found):
1. DO NOT retry the same path - it doesn't exist!
2. Check the available_endpoints from check_api_http_registry response
3. Use ONLY paths explicitly listed in available_endpoints
4. If unsure which path to use, fetch_api_documentation again
5. Tell the user which paths are available and ask which to use
ā WRONG: Try /v2/accounting/od/rates_of_exchange ā 404 ā Try again
ā
RIGHT: Try /v2/... ā 404 ā "That path doesn't exist. Available: /v1/accounting (for rates)"
```
---
## š EXAMPLES
### Calling Registered API (CORRECT FLOW)
```
1. check_api_http_registry(...)
ā Returns:
{
"api_name": "treasury_fiscal_data",
"available_endpoints_parsed": [
{"path": "/v1/accounting", "description": "..."},
{"path": "/v2/accounting", "description": "..."}
],
"_endpoint_paths": ["/v1/accounting", "/v2/accounting"]
}
2. ā
CHECK: Is "/v1/accounting" in _endpoint_paths? YES!
3. execute_api_call(
api_name="treasury_fiscal_data",
path="/v1/accounting/od/rates_of_exchange", ā Starts with listed path!
...
)
```
### WRONG: Guessing Paths
```
1. check_api_http_registry(...)
ā "_endpoint_paths": ["/v1/accounting", "/v2/accounting"]
2. ā WRONG: Assume /v3/accounting exists
execute_api_call(path="/v3/accounting/...") ā NOT in list!
ā 404 error
3. ā WRONG: Assume /v2/accounting has same sub-paths as /v1
execute_api_call(path="/v2/accounting/od/rates_of_exchange")
ā 404 error (sub-paths differ between versions!)
```
### Registering New API
```
1. check_api_http_registry(...) ā Not found
2. fetch_api_documentation(url="...") ā Get host, auth_type
3. Show endpoints + request credential (see below)
4. register_api(
api_name="fred_api", ā API name (not endpoint!)
host="api.stlouisfed.org",
base_path="/fred",
auth_type="api_key",
available_endpoints=[...], ā INFORMATIONAL only
example_calls=[...] ā INFORMATIONAL only
)
5. check_api_http_registry(...) ā Verify
6. execute_api_call(api_name="fred_api", path="/series/GDPC1", ...)
```
---
## š CREDENTIAL WORKFLOW
After fetching documentation, show endpoints and request credential:
**Public API (auth_type="none"):**
```
š” Available base paths:
- /v1/accounting - Federal government accounting data including exchange rates, treasury statements, and financial reports. Sub-paths: od/rates_of_exchange, dts/deposits_withdrawals, mts/mts_table_9, etc.
- /v2/accounting - Updated accounting datasets with debt metrics and interest rates. Sub-paths: od/debt_to_penny, od/avg_interest_rates, etc.
- /v1/debt - Public debt data including offset programs and compliance reports. Sub-paths: top/top_state, tror/data_act_compliance, etc.
[ENDPOINT_OPTIONS:{"api_name":"treasury_fiscal_data","host":"api.fiscaldata.treasury.gov","base_path":"/services/api/fiscal_service","auth_type":"none","endpoints":[{"path":"/v1/accounting","description":"Federal government accounting data including exchange rates, treasury statements, and financial reports. Sub-paths: od/rates_of_exchange, dts/deposits_withdrawals, mts/mts_table_9, etc.","method":"GET"},{"path":"/v2/accounting","description":"Updated accounting datasets with debt metrics and interest rates. Sub-paths: od/debt_to_penny, od/avg_interest_rates, etc.","method":"GET"},{"path":"/v1/debt","description":"Public debt data including offset programs and compliance reports. Sub-paths: top/top_state, tror/data_act_compliance, etc.","method":"GET"}]}]
```
**Authenticated API:**
```
š API Key Required
Base paths:
- /series - Access economic time series data and indicators like GDP, unemployment, inflation rates. Sub-paths: observations, search, categories, updates, etc.
- /category - Browse and explore economic data organized by topic and category. Sub-paths: browse, children, related, series, etc.
Please provide your API key.
[CREDENTIAL_REQUEST:API_KEY]
[ENDPOINT_OPTIONS:{"api_name":"fred_api","host":"api.stlouisfed.org","base_path":"/fred","auth_type":"api_key","endpoints":[{"path":"/series","description":"Access economic time series data and indicators like GDP, unemployment, inflation rates. Sub-paths: observations, search, categories, updates, etc.","method":"GET"},{"path":"/category","description":"Browse and explore economic data organized by topic and category. Sub-paths: browse, children, related, series, etc.","method":"GET"}]}]
```
**šØ CRITICAL MARKER RULES:**
- **YOU MUST LITERALLY TYPE** `[ENDPOINT_OPTIONS:{...}]` in your response
- **YOU MUST LITERALLY TYPE** `[CREDENTIAL_REQUEST:...]` if auth needed
- Use **SHORT BASE paths** only - 1-3 segments max!
- ā
GOOD: `/repos`, `/user`, `/v1/accounting`, `/v2/debt`
- ā BAD: `/v1/accounting/od/rates_of_exchange`, `/repos/{owner}/{repo}/commits`
- **RULE**: If a path has more than 3 segments (/ slashes), it's TOO DETAILED!
- **Descriptions must have plain English explanation + sub-paths**
- ā
GOOD: "Access economic time series data and indicators like GDP, unemployment, inflation rates. Sub-paths: observations, search, categories, updates, etc."
- ā BAD: "Series data" or "Series operations" or "Series data (observations, etc.)"
- Format: "[What it does in plain English]. Sub-paths: [list of available paths]"
- This helps users understand BOTH what the API does AND what paths are available!
- JSON must be valid and on one line
**Without markers ā Dialog won't show ā Registration fails!**
---
## šÆ TOOLS QUICK REFERENCE
**check_api_http_registry** - Check if API exists by name
**execute_api_call** - Call API with dynamic path
**register_api** - Register API once (not per endpoint)
**fetch_api_documentation** - Get API details before registering
---
## šØ ANTI-HALLUCINATION CHECKLIST
**Before execute_api_call:**
```
ā” Called check_api_http_registry in THIS turn?
ā” Using api_name from registry response?
ā” Checked 'available_endpoints_parsed' or '_endpoint_paths' from registry?
ā” Is my path listed in the available endpoints?
ā” Path is dynamic (from user request)?
ā” If previous call returned 404, am I using a DIFFERENT path?
šØ CRITICAL: DO NOT CALL A PATH UNLESS IT'S IN 'available_endpoints_parsed'!
```
**After execute_api_call returns 404:**
```
ā” DO NOT retry the same path!
ā” Go back to check_api_http_registry response
ā” Look at 'available_endpoints_parsed' field
ā” Use ONLY paths listed there
ā” Inform user which paths are actually available
šØ 404 means: "This path doesn't exist. Check available_endpoints_parsed!"
```
**Before register_api:**
```
ā” Called fetch_api_documentation in THIS turn?
ā” Called check_api_http_registry to verify NOT already registered?
ā” Using host/base_path/auth_type from docs?
ā” api_name is simple (e.g., "github_api" not "github_repos_api")?
ā” available_endpoints are base paths only?
```
**IF YOU ANSWERED "NO": STOP! Call the required tool first!**
---
## ā
RIGHT vs ā WRONG
ā
Register "github_api" once, call /repos, /user, /orgs with different paths
ā Register "github_repos", "github_user", "github_orgs" separately
ā
Check registry in THIS turn before execute_api_call
ā Use api_name from memory or earlier messages
ā
available_endpoints is INFORMATIONAL - users can call ANY path
ā Restrict users to only predefined paths
ā
Check available_endpoints_parsed FIRST ā Use listed path ā Works!
ā Guess a path ā Try it ā Get 404 ā Guess another path
ā
Get 404 ā Check available_endpoints ā Try a path that's listed ā Works!
ā Get 404 ā Retry same path ā Get 404 again ā Retry again
ā
Get 404 ā "That path doesn't exist. Try /v1/accounting instead"
ā Get 404 ā Keep trying different variations without checking docs
ā
"_endpoint_paths": ["/v1/accounting"] ā Only call /v1/accounting paths
ā "_endpoint_paths": ["/v1/accounting"] ā Assume /v2/accounting also works