budgetIdidentifierrequiredWhat identifies the budget, made by the application
Becomes the column budget_id of agent_budget.
What an agent, under a delegation or in a run, may spend of a meter in a window; it cannot be exceeded
Model identityAgent. Written in commons/data/models/identity-agent/mod.ts:165. Identified by budgetId.
budgetIdidentifierrequiredWhat identifies the budget, made by the application
Becomes the column budget_id of agent_budget.
budgetKeytextrequiredA hash of the agent, the delegation, the run, the meter and the window, unique
Becomes the column budget_key of agent_budget.
limitValueintegerrequiredHow much may be spent
Becomes the column limit_value of agent_budget.
metercode of meterrequiredWhat it counts
Becomes the column meter of agent_budget.
statuscode of useStatusrequiredWhether the budget is applied
Becomes the column status of agent_budget.
usedintegerrequiredHow much has been
Becomes the column used of agent_budget.
versionintegerrequiredWhich update it has had, so that two updates cannot both win
Becomes the column version of agent_budget.
windowKindcode of windowKindrequiredHow long it lasts
Becomes the column window_kind of agent_budget.
windowStartinstantrequiredWhen the window began
Becomes the column window_start of agent_budget.
agentoneThe agent To agent. Written at commons/data/models/identity-agent/mod.ts:205
delegationoptionalThe delegation it is for To delegation. Written at commons/data/models/identity-agent/mod.ts:165
runoptionalThe run it is for To agentRun. Written at commons/data/models/identity-agent/mod.ts:204
Projects to the table agent_budget with the primary key budget_id.
| Column | Type | Null | Role | From |
|---|---|---|---|---|
agent_principal_id | text | false | reference | agentBudget.agent |
budget_id | text | false | attribute | agentBudget.budgetId |
budget_key | text | false | attribute | agentBudget.budgetKey |
delegation_id | text | true | reference | agentBudget.delegation |
limit_value | integer | false | attribute | agentBudget.limitValue |
meter | text | false | attribute | agentBudget.meter |
run_agent_run_run_id | text | true | reference | agentBudget.run |
status | text | false | attribute | agentBudget.status |
used | integer | false | attribute | agentBudget.used |
version | integer | false | attribute | agentBudget.version |
window_kind | text | false | attribute | agentBudget.windowKind |
window_start | timestamp | false | attribute | agentBudget.windowStart |
CREATE TABLE IF NOT EXISTS "agent_budget" (
"budget_id" VARCHAR NOT NULL PRIMARY KEY,
"meter" VARCHAR NOT NULL,
"window_kind" VARCHAR NOT NULL,
"limit_value" INTEGER NOT NULL,
"used" INTEGER NOT NULL,
"window_start" TIMESTAMPTZ NOT NULL,
"version" INTEGER NOT NULL,
"status" VARCHAR NOT NULL,
"budget_key" VARCHAR NOT NULL,
"agent_principal_id" VARCHAR NOT NULL,
"delegation_id" VARCHAR,
"run_agent_run_run_id" VARCHAR,
CONSTRAINT "agent_budget_agent_principal_id_fk" FOREIGN KEY ("agent_principal_id") REFERENCES "agent" ("principal_id"),
CONSTRAINT "agent_budget_delegation_id_fk" FOREIGN KEY ("delegation_id") REFERENCES "delegation" ("delegation_id"),
CONSTRAINT "agent_budget_run_agent_run_run_id_fk" FOREIGN KEY ("run_agent_run_run_id") REFERENCES "agent_run" ("run_id"),
CONSTRAINT "agent_budget_budget_key_uq" UNIQUE ("budget_key"),
CONSTRAINT "agent_budget_meter_ck" CHECK ("meter" IN ('tool_calls', 'tokens', 'cost_micros', 'writes')),
CONSTRAINT "agent_budget_window_kind_ck" CHECK ("window_kind" IN ('run', 'hour', 'day', 'month', 'lifetime')),
CONSTRAINT "agent_budget_status_ck" CHECK ("status" IN ('active', 'retired'))
);CREATE TABLE IF NOT EXISTS "agent_budget" (
"budget_id" TEXT NOT NULL PRIMARY KEY,
"meter" TEXT NOT NULL,
"window_kind" TEXT NOT NULL,
"limit_value" INTEGER NOT NULL,
"used" INTEGER NOT NULL,
"window_start" TIMESTAMPTZ NOT NULL,
"version" INTEGER NOT NULL,
"status" TEXT NOT NULL,
"budget_key" TEXT NOT NULL,
"agent_principal_id" TEXT NOT NULL,
"delegation_id" TEXT,
"run_agent_run_run_id" TEXT,
CONSTRAINT "agent_budget_agent_principal_id_fk" FOREIGN KEY ("agent_principal_id") REFERENCES "agent" ("principal_id"),
CONSTRAINT "agent_budget_delegation_id_fk" FOREIGN KEY ("delegation_id") REFERENCES "delegation" ("delegation_id"),
CONSTRAINT "agent_budget_run_agent_run_run_id_fk" FOREIGN KEY ("run_agent_run_run_id") REFERENCES "agent_run" ("run_id"),
CONSTRAINT "agent_budget_budget_key_uq" UNIQUE ("budget_key"),
CONSTRAINT "agent_budget_meter_ck" CHECK ("meter" IN ('tool_calls', 'tokens', 'cost_micros', 'writes')),
CONSTRAINT "agent_budget_window_kind_ck" CHECK ("window_kind" IN ('run', 'hour', 'day', 'month', 'lifetime')),
CONSTRAINT "agent_budget_status_ck" CHECK ("status" IN ('active', 'retired'))
);CREATE TABLE IF NOT EXISTS "agent_budget" (
"budget_id" TEXT NOT NULL PRIMARY KEY,
"meter" TEXT NOT NULL,
"window_kind" TEXT NOT NULL,
"limit_value" INTEGER NOT NULL,
"used" INTEGER NOT NULL,
"window_start" TEXT NOT NULL,
"version" INTEGER NOT NULL,
"status" TEXT NOT NULL,
"budget_key" TEXT NOT NULL,
"agent_principal_id" TEXT NOT NULL,
"delegation_id" TEXT,
"run_agent_run_run_id" TEXT,
CONSTRAINT "agent_budget_agent_principal_id_fk" FOREIGN KEY ("agent_principal_id") REFERENCES "agent" ("principal_id"),
CONSTRAINT "agent_budget_delegation_id_fk" FOREIGN KEY ("delegation_id") REFERENCES "delegation" ("delegation_id"),
CONSTRAINT "agent_budget_run_agent_run_run_id_fk" FOREIGN KEY ("run_agent_run_run_id") REFERENCES "agent_run" ("run_id"),
CONSTRAINT "agent_budget_budget_key_uq" UNIQUE ("budget_key"),
CONSTRAINT "agent_budget_meter_ck" CHECK ("meter" IN ('tool_calls', 'tokens', 'cost_micros', 'writes')),
CONSTRAINT "agent_budget_window_kind_ck" CHECK ("window_kind" IN ('run', 'hour', 'day', 'month', 'lifetime')),
CONSTRAINT "agent_budget_status_ck" CHECK ("status" IN ('active', 'retired'))
);Read and written from TypeScript with the types the model gives: import { agentBudget } from "@intellectual-frontiers/data/sql/typed/models". Generated in commons/data/sql/typed/models/identity-agent.auto.ts: do not edit.
import { from } from "@intellectual-frontiers/data/sql/typed";
import { agentBudget } from "@intellectual-frontiers/data/sql/typed/models";
const rows = await from(agentBudget).select((s) => ({ budgetId: s.agentBudget.budgetId, meter: s.agentBudget.meter })).run(runner);