Intent Weighting is an advanced feature planned for AgenticAPI v0.4.0, designed to optimize action selection for AI agents by providing metadata that quantifies the cost, priority, and risk of each action. Using OpenAPI extensions like x-intent-weighting
, AgenticAPI will enable agents to make informed decisions when choosing among multiple actions (e.g., SUMMARIZE
vs. TRANSLATE
), balancing factors such as computational cost, urgency, or potential impact. This document explains the concept of intent weighting and provides an example of its planned implementation.
How Intent Weighting Works #
Intent Weighting attaches metadata to action verbs, describing their operational characteristics. This metadata helps agents evaluate trade-offs and select the most appropriate action based on context, constraints, or optimization goals. Key weighting factors include:
- Priority: Indicates urgency (e.g.,
high
,medium
,low
). - Cost Estimate: Quantifies resource usage, such as computational cost or API fees (e.g., in USD).
- Risk Profile: Assesses potential errors or side effects (e.g.,
low
,high
). - Execution Time: Estimates processing duration (e.g., in seconds).
The x-intent-weighting
OpenAPI extension will embed these factors in endpoint definitions, allowing agents to query and compare actions dynamically.
Example: OpenAPI with Intent Weighting #
The following OpenAPI snippet demonstrates how x-intent-weighting
will be applied to the SUMMARIZE
and TRANSLATE
verbs, enabling agents to choose based on cost and risk.
paths:
/document:
summarize:
x-action: summarize
x-category: compute
x-intent-weighting:
priority: high
cost_estimate: 0.01 # USD per request
risk_profile: low
execution_time: 2.0 # seconds
summary: Summarize a document
operationId: summarizeDocument
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
document_id:
type: string
format:
type: string
enum: [text, bullets]
max_words:
type: integer
style:
type: string
enum: [neutral, formal, casual]
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: object
properties:
summary:
type: string
title:
type: string
/translate:
translate:
x-action: translate
x-category: compute
x-intent-weighting:
priority: medium
cost_estimate: 0.05 # USD per request
risk_profile: medium
execution_time: 5.0 # seconds
summary: Translate a document
operationId: translateDocument
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
document_id:
type: string
target_language:
type: string
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: object
properties:
translated_text:
type: string
- x-intent-weighting:
SUMMARIZE
: High priority, low cost ($0.01), low risk, fast (2 seconds).TRANSLATE
: Medium priority, higher cost ($0.05), medium risk, slower (5 seconds).
- Agent Decision: An agent needing a quick, low-cost action might choose
SUMMARIZE
, while one requiring translation accepts higher cost and risk.
Example Agent Logic (Python):
import httpx
import json
def select_action(actions):
# Simulate agent choosing based on intent weighting
best_action = None
best_score = float('inf') # Minimize cost and time
for action in actions:
weighting = action.get('x-intent-weighting', {})
score = weighting.get('cost_estimate', 0) + weighting.get('execution_time', 0)
if score < best_score:
best_score = score
best_action = action
return best_action
# Fetch OpenAPI schema (planned DISCOVER /actions)
with httpx.Client() as client:
response = client.get("http://localhost:8000/openapi.json")
openapi = response.json()
# Extract actions (simulated for v0.4.0)
actions = [
openapi["paths"]["/document"]["summarize"],
openapi["paths"]["/translate"]["translate"]
]
# Select optimal action
chosen_action = select_action(actions)
print(f"Chosen action: {chosen_action['x-action']}")
Output:
Chosen action: summarize
This agent selects SUMMARIZE
due to its lower cost and execution time, demonstrating intent weighting in action.
Benefits #
- Optimized Decisions: Agents choose actions based on cost, risk, or priority.
- Dynamic Adaptation: Weighting supports context-aware action selection.
- Transparency: Metadata clarifies operational impacts for developers and agents.
Best Practices #
- Define Clear Metrics: Ensure
cost_estimate
andexecution_time
are accurate. - Balance Factors: Adjust
priority
andrisk_profile
to reflect use case needs. - Document Weighting: Include
x-intent-weighting
in all action endpoints. - Plan for v0.4.0: Prepare agents to parse weighting metadata when available.
Next Steps #
- Learn about Test Mode for action simulation.
- Explore Chaining for workflow orchestration.
- Try Implementing Custom Verbs with planned weighting.