The Asteroid Odyssey TypeScript SDK provides a simple way to interact with the Asteroid Agents API for triggering and monitoring agent executions, checking statuses, and retrieving results.
Agent Creation: Agents can only be created through the Asteroid Platform web interface. The API is designed for executing existing agents, not creating them.
Installation
Install Dependencies
Install the required packages:
npm install asteroid-odyssey typescript ts-node
Create Your File
Create a new file called example.ts
and add this code:
import {
AsteroidClient,
executeAgent,
waitForExecutionResult
} from 'asteroid-odyssey';
(async () => {
// Initialize the client with your API key
const client = AsteroidClient('YOUR_API_KEY');
// Execute an agent with prompt variables
const executionId = await executeAgent(client, 'YOUR_AGENT_ID', {
DATA: "First name: John, Last name: Smith"
});
console.log("Agent execution started:", executionId);
// Wait for execution to complete and retrieve the result
try {
const result = await waitForExecutionResult(client, executionId);
console.log("Agent result:", result);
} catch (err) {
console.error("Agent execution failed:", err);
}
})();
Run Your Code
Run the example using ts-node:
Replace YOUR_API_KEY
with your actual API key and YOUR_AGENT_ID
with the ID of an agent you’ve created in the Asteroid Platform.
API Reference
Client Creation
import { AsteroidClient } from 'asteroid-odyssey';
const client = AsteroidClient('YOUR_API_KEY');
Agent Execution
import { executeAgent } from 'asteroid-odyssey';
const executionId = await executeAgent(client, 'YOUR_AGENT_ID', {
DATA: "First name: John, Last name: Smith"
});
The executeAgent
function takes:
client
: The configured API client
agentId
: The ID of the agent to execute (found in the Asteroid platform)
executionData
: An object containing prompt variables that will be inserted into your agent’s prompt template
The example agent used in this documentation has a {{.DATA}}
prompt variable configured, which is why our examples use the DATA
parameter.
How Prompt Variables Work
When you create an agent, you define a prompt template with variables like {{.DATA}}
. The values you pass to executeAgent
replace these variables.
Example Agent Prompt:
Fill out the form!
These are the data to fill out:
{{.DATA}}
Make sure you fill out the data accurately including checking or leaving unchecked the checkboxes.
Then click on the Review button.
Execution Call:
const executionId = await executeAgent(client, 'your-agent-id', {
DATA: "First name: John, Last name: Smith, Email: john.smith@example.com"
});
Resulting Prompt (what the agent sees):
Fill out the form!
These are the data to fill out:
First name: John, Last name: Smith, Email: john.smith@example.com
Make sure you fill out the data accurately including checking or leaving unchecked the checkboxes.
Then click on the Review button.
Getting Results
Wait for Completion (Recommended)
import { waitForExecutionResult } from 'asteroid-odyssey';
const result = await waitForExecutionResult(client, executionId);
console.log("Final result:", result);
Check Status (Optional)
import { getExecutionStatus } from 'asteroid-odyssey';
const status = await getExecutionStatus(client, executionId);
console.log("Current status:", status.status);
Get Current Result (Optional)
import { getExecutionResult } from 'asteroid-odyssey';
const result = await getExecutionResult(client, executionId);
console.log("Current result:", result);
Error Handling
try {
const result = await waitForExecutionResult(client, executionId);
console.log(result);
} catch (error) {
console.error('Execution failed:', error);
}
Troubleshooting
Common Issues:
- Authentication errors: Verify your API key is correct and active
- Agent not found: Ensure the agent ID exists in your account and you have access to it. Remember, agents must be created through the web platform first.
- Execution timeout: Some tasks may take longer than expected
- Missing prompt variables: Ensure your execution data matches the prompt variables defined in your agent
For more help, visit the Asteroid Platform or check your execution logs there.