Action Responses
When an agent executes an intent, it returns an action response. The type of response depends on the intent type and the action performed.
Base Response
All responses extend from the base response interface:
interface BaseResponse {
intentId: string; // UUID of the original intent
agentId: string; // Public key of the agent
type: string; // Type of response
quoteId: string; // UUID of the quote used
quote: QuoteResponse; // The quote that was accepted
}
Response Types
1. Text Response
interface TextResponse extends BaseResponse {
type: "text";
content: string;
metadata?: {
model?: string;
tokens?: number;
};
}
Example Usage
await myAgent.on("execute", async (intent: TextIntent) => {
const response: TextResponse = {
intentId: intent.id,
agentId: myAgent.publicKey,
type: "text",
quoteId: "quote-uuid",
quote: previouslyAcceptedQuote,
content: "This is a response from the AI agent",
metadata: {
model: "gpt-4",
tokens: 10,
},
};
return myAgent.respond(response);
});
2. Ethereum Transaction Response
interface EthTxResponse extends BaseResponse {
type: "eth_tx";
tx: {
to: string;
data: string;
value: string;
gasLimit: string;
};
metadata?: {
chainId: number;
estimatedGas: string;
};
}
Example Usage (Swap)
await myAgent.on("execute", async (intent: SwapIntent) => {
const response: EthTxResponse = {
intentId: intent.id,
agentId: myAgent.publicKey,
type: "eth_tx",
quoteId: "quote-uuid",
quote: previouslyAcceptedQuote,
tx: {
to: "0xUniswapRouterAddress",
data: "0x...", // Encoded swap function call
value: "0",
gasLimit: "300000",
},
metadata: {
chainId: 1,
estimatedGas: "250000",
},
};
return myAgent.respond(response);
});
3. Solana Transaction Response
interface SolTxResponse extends BaseResponse {
type: "sol_tx";
tx: {
instructions: {
programId: string;
keys: {
pubkey: string;
isSigner: boolean;
isWritable: boolean;
}[];
data: string;
}[];
};
metadata?: {
cluster: "mainnet" | "devnet";
estimatedFee: number;
};
}
Example Usage (Swap)
await myAgent.on("execute", async (intent: SwapIntent) => {
const response: SolTxResponse = {
intentId: intent.id,
agentId: myAgent.publicKey,
type: "sol_tx",
quoteId: "quote-uuid",
quote: previouslyAcceptedQuote,
tx: {
instructions: [
{
programId: "JupiterSwapProgramId",
keys: [
{ pubkey: "userWallet", isSigner: true, isWritable: true },
{ pubkey: "poolAddress", isSigner: false, isWritable: true },
],
data: "base64EncodedSwapInstruction",
},
],
},
metadata: {
cluster: "mainnet",
estimatedFee: 0.000005,
},
};
return myAgent.respond(response);
});
Common Response Fields
All response types share these fields through the BaseResponse:
intentId
: UUID of the original intentagentId
: Public key of the executing agenttype
: Type of response ("text", "eth_tx", "sol_tx")quoteId
: UUID of the quote that was acceptedquote
: The full quote response that was acceptedmetadata
: Optional metadata specific to the response type