IF Commons GitHub

agentBudget

concept

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.

Governance: attributes

budgetIdidentifierrequired

What identifies the budget, made by the application

Becomes the column budget_id of agent_budget.

Written at commons/data/models/identity-agent/mod.ts:168

budgetKeytextrequired

A hash of the agent, the delegation, the run, the meter and the window, unique

Becomes the column budget_key of agent_budget.

Written at commons/data/models/identity-agent/mod.ts:176

limitValueintegerrequired

How much may be spent

Becomes the column limit_value of agent_budget.

Written at commons/data/models/identity-agent/mod.ts:171

metercode of meterrequired

What it counts

Becomes the column meter of agent_budget.

Written at commons/data/models/identity-agent/mod.ts:169

statuscode of useStatusrequired

Whether the budget is applied

Becomes the column status of agent_budget.

Written at commons/data/models/identity-agent/mod.ts:175

usedintegerrequired

How much has been

Becomes the column used of agent_budget.

Written at commons/data/models/identity-agent/mod.ts:172

versionintegerrequired

Which update it has had, so that two updates cannot both win

Becomes the column version of agent_budget.

Written at commons/data/models/identity-agent/mod.ts:174

windowKindcode of windowKindrequired

How long it lasts

Becomes the column window_kind of agent_budget.

Written at commons/data/models/identity-agent/mod.ts:170

windowStartinstantrequired

When the window began

Becomes the column window_start of agent_budget.

Written at commons/data/models/identity-agent/mod.ts:173

Governance: relationships

agentone

The agent To agent. Written at commons/data/models/identity-agent/mod.ts:205

delegationoptional

The delegation it is for To delegation. Written at commons/data/models/identity-agent/mod.ts:165

runoptional

The run it is for To agentRun. Written at commons/data/models/identity-agent/mod.ts:204

Logical: the table

Projects to the table agent_budget with the primary key budget_id.

ColumnTypeNullRoleFrom
agent_principal_idtextfalsereferenceagentBudget.agent
budget_idtextfalseattributeagentBudget.budgetId
budget_keytextfalseattributeagentBudget.budgetKey
delegation_idtexttruereferenceagentBudget.delegation
limit_valueintegerfalseattributeagentBudget.limitValue
metertextfalseattributeagentBudget.meter
run_agent_run_run_idtexttruereferenceagentBudget.run
statustextfalseattributeagentBudget.status
usedintegerfalseattributeagentBudget.used
versionintegerfalseattributeagentBudget.version
window_kindtextfalseattributeagentBudget.windowKind
window_starttimestampfalseattributeagentBudget.windowStart

Physical: SQL

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'))
);

Physical: the typed table

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);

Titles, headings, exports, tables, columns and requirements. Esc closes.