@tyrpay/buyer-skill
v0.1.5
Published
LLM-callable buyer-side tools for the TyrPay Phase 1 protocol.
Readme
@tyrpay/buyer-skill
LLM-callable buyer-side tools for the TyrPay Phase 1 protocol.
This package wraps a configured BuyerSdk into structured tool definitions that
an agent can pass directly to Claude-style or OpenAI-style tool calling.
What This Package Exports
createBuyerTools(sdk): returns six buyer-side toolsBuyerTool: the shared tool shape used by this package
Tool names:
tyrpay_post_tasktyrpay_fund_tasktyrpay_check_tasktyrpay_refund_tasktyrpay_list_taskstyrpay_ready
Installation
pnpm add @tyrpay/buyer-skill @tyrpay/buyer-sdk @tyrpay/storage-adapter@tyrpay/buyer-skill does not construct wallets, providers, or storage for you.
You must configure BuyerSdk first.
End-to-End Flow
Typical buyer-side flow:
- Configure
BuyerSdkwith a signer, settlement contract address, and storage adapter. - Call
tyrpay_readyonce to verify signer and provider connectivity. - Call
tyrpay_post_taskto create the task intent. - Either let
tyrpay_post_taskauto-wait and auto-fund, or setcreateOnly: trueand calltyrpay_fund_tasklater. - Share the returned
taskIdwith the seller through your own application or messaging layer. - Use
tyrpay_check_taskortyrpay_list_tasksto monitor progress with both raw protocol status and buyer-facing status fields. - If the seller or verifier misses a protocol deadline, use
tyrpay_refund_task.
buyer-skill does not notify the seller for you. Buyer/seller coordination is
an application responsibility outside this package.
Prerequisites
Before calling createBuyerTools, prepare:
- an EVM signer connected to a provider
- the deployed TyrPay settlement contract address
- a storage adapter that can read commitment objects
Minimal BuyerSdk setup:
import { BuyerSdk } from "@tyrpay/buyer-sdk";
import { MemoryStorageAdapter } from "@tyrpay/storage-adapter";
const sdk = new BuyerSdk({
signer,
settlementAddress,
storage: new MemoryStorageAdapter()
});Basic Usage
Raw tool definitions
import { createBuyerTools } from "@tyrpay/buyer-skill";
const tools = createBuyerTools(sdk);Each returned tool has:
namedescriptioninputSchemaexecute(input)
Claude-style tool format
const claudeTools = createBuyerTools(sdk).map((tool) => ({
name: tool.name,
description: tool.description,
input_schema: tool.inputSchema
}));OpenAI-style tool format
const openAITools = createBuyerTools(sdk).map((tool) => ({
type: "function",
function: {
name: tool.name,
description: tool.description,
parameters: tool.inputSchema
}
}));Executing a returned tool call
const tools = createBuyerTools(sdk);
const tool = tools.find((entry) => entry.name === "tyrpay_post_task");
if (!tool) {
throw new Error("buyer tool not found");
}
const result = await tool.execute({
seller: "0x1111111111111111111111111111111111111111",
token: "0x2222222222222222222222222222222222222222",
amount: "1000000",
deadline: "1760000000000",
createOnly: true,
expectations: {
acceptedHosts: ["api.openai.com"],
acceptedPaths: ["/v1/chat/completions"],
acceptedMethods: ["POST"],
acceptedModels: ["gpt-4o-mini"],
requireNonZeroMinUsage: true
}
});Tool Semantics
tyrpay_post_task
Create a task intent and optionally continue all the way to funding.
- create the task intent on-chain
- optionally wait for seller commitment submission
- optionally validate the commitment against buyer expectations
- optionally fund the task
Use this as the primary buyer entrypoint when the agent is creating a new task.
Set createOnly: true when you need a non-blocking flow and want funding to be a separate explicit step.
Returns:
taskId: on-chain task identifiertaskNonce: on-chain task nonce assigned at task creationcreateTxHash: transaction hash forcreateTaskIntentfundTxHash: transaction hash forfundTaskwhen funding happened in this callcommitmentHash: seller commitment hash accepted by the buyer flow when availablecommitmentURI: seller commitment URI accepted by the buyer flow when availabletimedOut:truewhen the task was created but the seller did not respond before the wait window endeduserStatus: buyer-facing status, eitherWAITING_FOR_SELLERorIN_PROGRESSuserMessage: buyer-facing explanation of what happens next
tyrpay_fund_task
Manual funding step for tasks that already have a submitted commitment.
Use this when:
tyrpay_post_taskwas called withcreateOnly: truetyrpay_post_taskreturnedtimedOut: true- the agent wants explicit control over when payment is locked
Returns:
taskId: funded task identifierfundTxHash: transaction hash forfundTaskcommitmentHash: seller commitment hash that passed validationcommitmentURI: seller commitment URI that passed validationuserStatus:IN_PROGRESSuserMessage: buyer-facing explanation that execution can begin
tyrpay_check_task
Returns the current on-chain task plus both machine-friendly and buyer-facing status fields.
Derived protocol statuses currently exposed:
EXECUTINGVERIFIED_PASSVERIFIED_FAILEXPIRED
Buyer-facing statuses currently exposed:
WAITING_FOR_SELLERREADY_TO_FUNDIN_PROGRESSAWAITING_VERIFICATIONCOMPLETEDREFUNDEDEXPIREDVERIFIED_PASSVERIFIED_FAIL
Returns:
- all normalized on-chain task fields from
BuyerSdk.getTask(...) derivedStatus: current derived status used for buyer-facing monitoringuserStatus: simplified status for end-user messaginguserMessage: short explanation of the current stage
tyrpay_refund_task
Requests a refund through one of the two timeout paths:
proof_submission_deadlineverification_timeout
Returns:
txHash: refund transaction hashuserStatus: currentlyREFUND_IN_PROGRESSuserMessage: short explanation that refund was requested and still needs confirmation
tyrpay_list_tasks
Batch status lookup for multiple task IDs.
Returns:
- an array of task records in the same order as the input
taskIds - each record contains all normalized task fields plus
derivedStatus,userStatus, anduserMessage
tyrpay_ready
Readiness check for buyer-side agent wiring.
Returns:
ok: alwaystruewhen the check succeedssignerAddress: buyer signer address in useuserStatus:READYuserMessage: confirmation that signer and provider are reachable
Notes For Agent Authors
- Runtime validation rejects malformed tool arguments before they hit ethers or the SDK.
- Tool failures throw
BuyerSkillToolErrorwithcode,field,suggestion, andretryablemetadata. - Pass buyer-side expectations whenever the upstream API, method, model, or verifier must be constrained.
deadlineis the execution deadline in Unix milliseconds, not a human string.
Related Packages
@tyrpay/buyer-sdk: on-chain buyer workflow and validation@tyrpay/agent-kit: prebuilt Claude/OpenAI wrappers if you do not want to map the tool shape yourself
