Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
290 changes: 149 additions & 141 deletions api_v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3180,9 +3180,13 @@
"runningBudget" : {
"$ref" : "#/components/schemas/SessionRunningBudget",
"description" : "A counter for the session's running budget. See SessionRunningBudget for more information"
},
"budgetSettings" : {
"$ref" : "#/components/schemas/SessionBudgetSettings",
"description" : "The budget settings for this session"
}
},
"required" : [ "agents", "base", "runningBudget", "threads" ],
"required" : [ "agents", "base", "budgetSettings", "runningBudget", "threads" ],
"title" : "SessionStateExtended"
},
"SessionAgentState" : {
Expand Down Expand Up @@ -3345,6 +3349,10 @@
"$ref" : "#/components/schemas/SessionRunningBudget",
"description" : "A counter for the agent's running budget. See SessionRunningBudget for more information"
},
"budgetSettings" : {
"$ref" : "#/components/schemas/GraphAgentBudgetSettings",
"description" : "The budget settings for this agent"
},
"annotations" : {
"type" : "object",
"additionalProperties" : {
Expand All @@ -3354,7 +3362,7 @@
"title" : "LinkedHashMap<String,String>"
}
},
"required" : [ "annotations", "links", "name", "registryAgentIdentifier", "runningBudget", "status" ],
"required" : [ "annotations", "budgetSettings", "links", "name", "registryAgentIdentifier", "runningBudget", "status" ],
"title" : "SessionAgentState"
},
"RegistryAgentIdentifier" : {
Expand Down Expand Up @@ -3468,6 +3476,145 @@
"required" : [ "amount", "description", "timestamp" ],
"title" : "SessionBudgetClaim"
},
"GraphAgentBudgetSettings" : {
"type" : "object",
"properties" : {
"budget" : {
"type" : "integer",
"description" : "The budget for this specific agent. The value is specified in micro cents. $1.00 is 100000000 and $0.01 is 1000000.",
"title" : "AgentBudgetUnit"
},
"exhaustionBehavior" : {
"anyOf" : [ {
"type" : "object",
"description" : "Once's the agent's budget is exhausted, it will consume the session's budget. If the session's budget is also exhausted, the session's exhaustion behavior will be applied. If a claim is made that cannot be fully fulfilled by the agent's budget, the remainder will be taken from the session's budget.",
"properties" : {
"type" : {
"type" : "string",
"enum" : [ "consume_session" ],
"title" : "String"
}
},
"required" : [ "type" ],
"title" : "consume_session"
}, {
"type" : "object",
"description" : "Once the agent's budget is less than the specified minimum amount, the agent will be killed. The higher the minimum is the lower the chance of overclaiming. This behavior will stop the agent claiming from the session's budget",
"properties" : {
"type" : {
"type" : "string",
"enum" : [ "kill" ],
"title" : "String"
},
"minimum" : {
"type" : "integer",
"description" : "The minimum value, specified in micro cents. $1.00 is 100000000 and $0.01 is 1000000.",
"title" : "AgentBudgetUnit"
},
"force" : {
"type" : "boolean",
"description" : "If this is true, the agent will be killed immediately. If this is false, the agent will only be killed if the claim requests for automatic closing.",
"title" : "Boolean"
},
"forceDelay" : {
"type" : "string",
"description" : "If force killing is enabled, it will be delayed by this amount before the agent is killed. If this delay is too low the agent may be killed before it handles to response to a claim",
"title" : "Duration"
}
},
"required" : [ "force", "minimum", "type" ],
"title" : "kill"
} ],
"description" : "The behavior of agent budget exhaustion, defaults to consuming session budget.",
"discriminator" : {
"propertyName" : "type"
},
"title" : "AgentBudgetExhaustionBehavior"
}
},
"title" : "GraphAgentBudgetSettings"
},
"SessionBudgetSettings" : {
"type" : "object",
"description" : "Budgets settings for this session. Budgets are consumed by agents in the session.",
"properties" : {
"budget" : {
"type" : "integer",
"description" : "\n This budget is shared across all agents in the session and can be used by any agent configured to consume the shared budget.\n \n The value is specified in micro cents. $1.00 is 100000000 and $0.01 is 1000000.\") \n ",
"title" : "AgentBudgetUnit"
},
"exhaustionBehavior" : {
"anyOf" : [ {
"type" : "object",
"description" : "Once the session budget drops below the specified minimum, agents that claim for it will be killed. The higher the minimum is the lower the chance of overclaiming.",
"properties" : {
"type" : {
"type" : "string",
"enum" : [ "kill_agent" ],
"title" : "String"
},
"minimum" : {
"type" : "integer",
"description" : "The minimum value, specified in micro cents. $1.00 is 100000000 and $0.01 is 1000000.",
"title" : "AgentBudgetUnit"
},
"force" : {
"type" : "boolean",
"description" : "If this is true, when an agent claims from the session budget that is below the minimum, the agent will be killed immediately. If this is false, the agent will only be killed if the agent requests for automatic closing.",
"title" : "Boolean"
},
"forceDelay" : {
"type" : "string",
"description" : "If force killing is enabled, it will be delayed by this amount before the agent is killed. If this delay is too low the agent may be killed before it handles to response to a claim",
"title" : "Duration"
}
},
"required" : [ "force", "minimum", "type" ],
"title" : "kill_agent"
}, {
"type" : "object",
"description" : "Once the session budget drops below the specified minimum, agents that claim for it will trigger the session to be killed. The higher the minimum is the lower the chance of overclaiming.",
"properties" : {
"type" : {
"type" : "string",
"enum" : [ "kill_session" ],
"title" : "String"
},
"minimum" : {
"type" : "integer",
"description" : "The minimum value, specified in micro cents. $1.00 is 100000000 and $0.01 is 1000000.",
"title" : "AgentBudgetUnit"
},
"delay" : {
"type" : "string",
"description" : "The delay before the session is killed. If this delay is too low, the agent whose claim triggered this may be killed before it receives the response to that claim",
"title" : "Duration"
}
},
"required" : [ "minimum", "type" ],
"title" : "kill_session"
}, {
"type" : "object",
"description" : "Once the session budget is exhausted and claimed from, a warning will be produced. This behavior has a high risk of overclaiming.",
"properties" : {
"type" : {
"type" : "string",
"enum" : [ "warn" ],
"title" : "String"
}
},
"required" : [ "type" ],
"title" : "warn"
} ],
"description" : "\n The behavior for agents consuming from this budget after it has been exhausted. Note that this behavior\n only applies to agents that consume from the session budgets. Agents that have their own budget will first \n perform behaviors described by the agent's own budget settings.\n ",
"discriminator" : {
"propertyName" : "type"
},
"title" : "SessionBudgetExhaustionBehavior"
}
},
"title" : "SessionBudgetSettings"
},
"SessionAgentUsageReport" : {
"type" : "object",
"properties" : {
Expand Down Expand Up @@ -4677,64 +4824,6 @@
"required" : [ "configurationName", "modelName" ],
"title" : "GraphAgentProxyRequest"
},
"GraphAgentBudgetSettings" : {
"type" : "object",
"properties" : {
"budget" : {
"type" : "integer",
"description" : "The budget for this specific agent. The value is specified in micro cents. $1.00 is 100000000 and $0.01 is 1000000.",
"title" : "AgentBudgetUnit"
},
"exhaustionBehavior" : {
"anyOf" : [ {
"type" : "object",
"description" : "Once's the agent's budget is exhausted, it will consume the session's budget. If the session's budget is also exhausted, the session's exhaustion behavior will be applied. If a claim is made that cannot be fully fulfilled by the agent's budget, the remainder will be taken from the session's budget.",
"properties" : {
"type" : {
"type" : "string",
"enum" : [ "consume_session" ],
"title" : "String"
}
},
"required" : [ "type" ],
"title" : "consume_session"
}, {
"type" : "object",
"description" : "Once the agent's budget is less than the specified minimum amount, the agent will be killed. The higher the minimum is the lower the chance of overclaiming. This behavior will stop the agent claiming from the session's budget",
"properties" : {
"type" : {
"type" : "string",
"enum" : [ "kill" ],
"title" : "String"
},
"minimum" : {
"type" : "integer",
"description" : "The minimum value, specified in micro cents. $1.00 is 100000000 and $0.01 is 1000000.",
"title" : "AgentBudgetUnit"
},
"force" : {
"type" : "boolean",
"description" : "If this is true, the agent will be killed immediately. If this is false, the agent will only be killed if the claim requests for automatic closing.",
"title" : "Boolean"
},
"forceDelay" : {
"type" : "string",
"description" : "If force killing is enabled, it will be delayed by this amount before the agent is killed. If this delay is too low the agent may be killed before it handles to response to a claim",
"title" : "Duration"
}
},
"required" : [ "force", "minimum", "type" ],
"title" : "kill"
} ],
"description" : "The behavior of agent budget exhaustion, defaults to consuming session budget.",
"discriminator" : {
"propertyName" : "type"
},
"title" : "AgentBudgetExhaustionBehavior"
}
},
"title" : "GraphAgentBudgetSettings"
},
"GraphAgentTool" : {
"type" : "object",
"properties" : {
Expand Down Expand Up @@ -4972,87 +5061,6 @@
"required" : [ "url" ],
"title" : "SessionEndWebhook"
},
"SessionBudgetSettings" : {
"type" : "object",
"description" : "Budgets settings for this session. Budgets are consumed by agents in the session.",
"properties" : {
"budget" : {
"type" : "integer",
"description" : "\n This budget is shared across all agents in the session and can be used by any agent configured to consume the shared budget.\n \n The value is specified in micro cents. $1.00 is 100000000 and $0.01 is 1000000.\") \n ",
"title" : "AgentBudgetUnit"
},
"exhaustionBehavior" : {
"anyOf" : [ {
"type" : "object",
"description" : "Once the session budget drops below the specified minimum, agents that claim for it will be killed. The higher the minimum is the lower the chance of overclaiming.",
"properties" : {
"type" : {
"type" : "string",
"enum" : [ "kill_agent" ],
"title" : "String"
},
"minimum" : {
"type" : "integer",
"description" : "The minimum value, specified in micro cents. $1.00 is 100000000 and $0.01 is 1000000.",
"title" : "AgentBudgetUnit"
},
"force" : {
"type" : "boolean",
"description" : "If this is true, when an agent claims from the session budget that is below the minimum, the agent will be killed immediately. If this is false, the agent will only be killed if the agent requests for automatic closing.",
"title" : "Boolean"
},
"forceDelay" : {
"type" : "string",
"description" : "If force killing is enabled, it will be delayed by this amount before the agent is killed. If this delay is too low the agent may be killed before it handles to response to a claim",
"title" : "Duration"
}
},
"required" : [ "force", "minimum", "type" ],
"title" : "kill_agent"
}, {
"type" : "object",
"description" : "Once the session budget drops below the specified minimum, agents that claim for it will trigger the session to be killed. The higher the minimum is the lower the chance of overclaiming.",
"properties" : {
"type" : {
"type" : "string",
"enum" : [ "kill_session" ],
"title" : "String"
},
"minimum" : {
"type" : "integer",
"description" : "The minimum value, specified in micro cents. $1.00 is 100000000 and $0.01 is 1000000.",
"title" : "AgentBudgetUnit"
},
"delay" : {
"type" : "string",
"description" : "The delay before the session is killed. If this delay is too low, the agent whose claim triggered this may be killed before it receives the response to that claim",
"title" : "Duration"
}
},
"required" : [ "minimum", "type" ],
"title" : "kill_session"
}, {
"type" : "object",
"description" : "Once the session budget is exhausted and claimed from, a warning will be produced. This behavior has a high risk of overclaiming.",
"properties" : {
"type" : {
"type" : "string",
"enum" : [ "warn" ],
"title" : "String"
}
},
"required" : [ "type" ],
"title" : "warn"
} ],
"description" : "\n The behavior for agents consuming from this budget after it has been exhausted. Note that this behavior\n only applies to agents that consume from the session budgets. Agents that have their own budget will first \n perform behaviors described by the agent's own budget settings.\n ",
"discriminator" : {
"propertyName" : "type"
},
"title" : "SessionBudgetExhaustionBehavior"
}
},
"title" : "SessionBudgetSettings"
},
"SessionRequest" : {
"type" : "object",
"properties" : {
Expand Down
24 changes: 24 additions & 0 deletions src/lib/session.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,25 @@ export type SessionAgentState = components['schemas']['SessionAgentState'];
export type SessionAgentStatus = SessionAgentState['status'];

export type SessionThread = components['schemas']['SessionThread'];
export type SessionStateBase = components['schemas']['SessionStateBase'];
export type SessionStateExtended = components['schemas']['SessionStateExtended'];

export class Session {
private socket: WebSocket;
private server: CoralServer;
public connected = $state(false);

readonly sessionId: string;
readonly namespace: string;

public get annotations(): SessionStateBase['annotations'] | undefined {
return this.server.sessions[this.sessionId]?.annotations;
}
public get timestamp(): SessionStateBase['timestamp'] | undefined {
return this.server.sessions[this.sessionId]?.timestamp;
}
public extended: Omit<SessionStateExtended, 'base' | 'threads' | 'agents'> | null = $state(null);

public agentId: string | null = $state(null);

public possessed: string | null = $state(null);
Expand All @@ -40,6 +51,7 @@ export class Session {
sessionId: string;
server: CoralServer;
}) {
this.server = server;
let markInitialStateReady: (value?: any) => void;
const initialStateReady = new Promise((resolve) => {
markInitialStateReady = resolve;
Expand All @@ -63,6 +75,16 @@ export class Session {
this.socket.close();
return;
}

if (this.sessionId in this.server.sessions) {
this.server.sessions[this.sessionId] = res.data.base;
}

this.extended = {
budgetSettings: res.data.budgetSettings,
runningBudget: res.data.runningBudget
};

this.threads = Object.fromEntries(
res.data.threads.map((thread) => {
return [
Expand Down Expand Up @@ -119,6 +141,8 @@ export class Session {
}

switch (data.type) {
case 'agent_budget_claim':
break;
case 'agent_connected':
if (!this.agents[data.name]) {
toast.warning("Got agent update about an agent we don't know!");
Expand Down
Loading