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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion backend/windmill-api-groups/src/folders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ struct FolderUsage {
pub flows: i64,
pub apps: i64,
pub resources: i64,
pub agents: i64,
pub variables: i64,
}
async fn get_folder_usage(
Expand Down Expand Up @@ -749,8 +750,19 @@ async fn get_folder_usage(
.await?
.unwrap_or(0);

// A saved AI agent is an `ai_agent` resource, but it is listed and used as an item of
// its own, so it is counted apart rather than among the credentials.
let agents = sqlx::query_scalar!(
"SELECT count(path) FROM resource WHERE path LIKE 'f/' || $1 || '%' AND resource_type = 'ai_agent' AND workspace_id = $2",
name,
w_id
)
.fetch_one(&mut *tx)
.await?
.unwrap_or(0);

let resources = sqlx::query_scalar!(
"SELECT count(path) FROM resource WHERE path LIKE 'f/' || $1 || '%' AND workspace_id = $2",
"SELECT count(path) FROM resource WHERE path LIKE 'f/' || $1 || '%' AND resource_type IS DISTINCT FROM 'ai_agent' AND workspace_id = $2",
name,
w_id
)
Expand All @@ -774,6 +786,7 @@ async fn get_folder_usage(
schedules,
apps: apps + raw_apps,
resources,
agents,
variables,
}))
}
Expand Down
5 changes: 5 additions & 0 deletions backend/windmill-api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25045,6 +25045,10 @@ paths:
type: number
resources:
type: number
description: resources other than AI agents
agents:
type: number
description: saved AI agents (resources of type `ai_agent`)
variables:
type: number
schedules:
Expand All @@ -25054,6 +25058,7 @@ paths:
- flows
- apps
- resources
- agents
- variables
- schedules

Expand Down
68 changes: 65 additions & 3 deletions backend/windmill-api/src/hub_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ pub fn workspaced_service() -> Router {
)
.route("/resource_types", post(publish_resource_type))
.route("/resources", post(publish_resources))
.route("/agents", post(publish_agents))
.route(
"/projects/{slug}/agent_recording",
post(publish_agent_recording),
)
.route("/triggers", post(publish_triggers))
.route("/migrations", post(publish_migrations))
.route("/projects/{slug}/export", get(get_project_export))
Expand Down Expand Up @@ -384,10 +389,10 @@ struct ProjectLogoBody {
logo: Option<Option<ProjectLogoInner>>,
}

fn deserialize_explicit<'de, D: Deserializer<'de>>(
fn deserialize_explicit<'de, T: Deserialize<'de>, D: Deserializer<'de>>(
d: D,
) -> Result<Option<Option<ProjectLogoInner>>, D::Error> {
Option::<ProjectLogoInner>::deserialize(d).map(Some)
) -> Result<Option<Option<T>>, D::Error> {
Option::<T>::deserialize(d).map(Some)
}

// Mirrors the Hub's own limits so an oversized/invalid payload is rejected
Expand Down Expand Up @@ -485,6 +490,63 @@ async fn publish_resources(
.await
}

// A saved agent is an `ai_agent` resource whose value is the product: its prompt, model and
// tools. Unlike the stubs above it ships whole, since it holds no credential, only `$res:`
// references to the provider and to what its tools take, which travel as stubs.
#[derive(Deserialize, Serialize)]
struct PublishAgentBody {
path: String,
#[serde(skip_serializing_if = "Option::is_none")]
source_path: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
summary: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
value: serde_json::Value,
}

// Full-set sync, as for triggers: the agents the folder holds now, absent ones removed.
#[derive(Deserialize, Serialize)]
struct PublishAgentsBody {
agents: Vec<PublishAgentBody>,
project_slug: ProjectSlug,
}

async fn publish_agents(
ctx: HubPublishCtx,
Json(body): Json<PublishAgentsBody>,
) -> Result<impl IntoResponse, Error> {
ctx.post(&format!("/projects/{}/agents", body.project_slug), &body)
.await
}

// The demo of an agent is a recorded conversation, kept on the agent's row of the draft.
// Double-Option, as for the logo: `recording: null` clears it, and a body without the key
// is refused rather than read as that.
#[derive(Deserialize, Serialize)]
struct AgentRecordingBody {
path: String,
#[serde(default, deserialize_with = "deserialize_explicit")]
recording: Option<Option<serde_json::Value>>,
}

async fn publish_agent_recording(
ctx: HubPublishCtx,
Path((_workspace, slug)): Path<(String, ProjectSlug)>,
Json(body): Json<AgentRecordingBody>,
) -> Result<impl IntoResponse, Error> {
let Some(recording) = body.recording else {
return Err(Error::BadRequest(
"recording field is required: an object to set it, or null to clear it".to_string(),
));
};
ctx.post(
&format!("/projects/{}/agent_recording", slug),
&serde_json::json!({ "path": body.path, "recording": recording }),
)
.await
}

#[derive(Deserialize, Serialize)]
struct PublishTriggerBody {
path: String,
Expand Down
67 changes: 67 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,46 @@
"types": "./package/components/common/badge/Badge.svelte.d.ts",
"svelte": "./package/components/common/badge/Badge.svelte",
"default": "./package/components/common/badge/Badge.svelte"
},
"./components/copilot/chat/AIChatMessage.svelte": {
"types": "./package/components/copilot/chat/AIChatMessage.svelte.d.ts",
"svelte": "./package/components/copilot/chat/AIChatMessage.svelte",
"default": "./package/components/copilot/chat/AIChatMessage.svelte"
},
"./components/copilot/chat/ToolGroupDisplay.svelte": {
"types": "./package/components/copilot/chat/ToolGroupDisplay.svelte.d.ts",
"svelte": "./package/components/copilot/chat/ToolGroupDisplay.svelte",
"default": "./package/components/copilot/chat/ToolGroupDisplay.svelte"
},
"./components/copilot/chat/ChatTypingIndicator.svelte": {
"types": "./package/components/copilot/chat/ChatTypingIndicator.svelte.d.ts",
"svelte": "./package/components/copilot/chat/ChatTypingIndicator.svelte",
"default": "./package/components/copilot/chat/ChatTypingIndicator.svelte"
},
"./components/copilot/chat/chatViewHost": {
"types": "./package/components/copilot/chat/chatViewHost.d.ts",
"default": "./package/components/copilot/chat/chatViewHost.js"
},
"./components/copilot/chat/readOnlyChatViewHost.svelte": {
"types": "./package/components/copilot/chat/readOnlyChatViewHost.svelte.d.ts",
"default": "./package/components/copilot/chat/readOnlyChatViewHost.svelte.js"
},
"./components/copilot/chat/toolGroups": {
"types": "./package/components/copilot/chat/toolGroups.d.ts",
"default": "./package/components/copilot/chat/toolGroups.js"
},
"./components/copilot/chat/shared": {
"types": "./package/components/copilot/chat/shared.d.ts",
"default": "./package/components/copilot/chat/shared.js"
},
"./components/recording/AgentRecordingTranscript.svelte": {
"types": "./package/components/recording/AgentRecordingTranscript.svelte.d.ts",
"svelte": "./package/components/recording/AgentRecordingTranscript.svelte",
"default": "./package/components/recording/AgentRecordingTranscript.svelte"
},
"./components/recording/agentRecording": {
"types": "./package/components/recording/agentRecording.d.ts",
"default": "./package/components/recording/agentRecording.js"
}
},
"files": [
Expand Down Expand Up @@ -651,6 +691,33 @@
],
"components/common/badge/Badge.svelte": [
"./package/components/common/badge/Badge.svelte.d.ts"
],
"components/copilot/chat/AIChatMessage.svelte": [
"./package/components/copilot/chat/AIChatMessage.svelte.d.ts"
],
"components/copilot/chat/ToolGroupDisplay.svelte": [
"./package/components/copilot/chat/ToolGroupDisplay.svelte.d.ts"
],
"components/copilot/chat/ChatTypingIndicator.svelte": [
"./package/components/copilot/chat/ChatTypingIndicator.svelte.d.ts"
],
"components/copilot/chat/chatViewHost": [
"./package/components/copilot/chat/chatViewHost.d.ts"
],
"components/copilot/chat/readOnlyChatViewHost.svelte": [
"./package/components/copilot/chat/readOnlyChatViewHost.svelte.d.ts"
],
"components/copilot/chat/toolGroups": [
"./package/components/copilot/chat/toolGroups.d.ts"
],
"components/copilot/chat/shared": [
"./package/components/copilot/chat/shared.d.ts"
],
"components/recording/AgentRecordingTranscript.svelte": [
"./package/components/recording/AgentRecordingTranscript.svelte.d.ts"
],
"components/recording/agentRecording": [
"./package/components/recording/agentRecording.d.ts"
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/components/FolderUsageInfo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
order?: any;
}
let { name, tabular = false, order = ['scripts', 'flows', 'apps', 'schedules', 'variables', 'resources'] }: Props = $props();
let { name, tabular = false, order = ['scripts', 'flows', 'apps', 'agents', 'schedules', 'variables', 'resources'] }: Props = $props();
let usage: Record<string, number> = $state({})
Expand Down
95 changes: 95 additions & 0 deletions frontend/src/lib/components/aiAgentResult.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
formatTokenCount,
isAgentStream,
parseAgentResult,
readAgentTurn,
summarizeAgentResult
} from './aiAgentResult'

Expand Down Expand Up @@ -265,3 +266,97 @@ describe('coercing messages at the boundary', () => {
])
})
})

const call = (id: string, name: string, args: unknown) => ({
id,
type: 'function',
function: { name, arguments: JSON.stringify(args) }
})

describe('readAgentTurn', () => {
it('reads the tools this turn called and its answer', () => {
const turn = readAgentTurn({
output: 'Found it.',
messages: [
{ role: 'user', content: 'Where is my order?' },
{ role: 'assistant', tool_calls: [call('a', 'get_order', { id: 1 })] },
{ role: 'tool', tool_call_id: 'a', content: '{"status":"shipped"}' },
{ role: 'assistant', content: 'Found it.' }
]
})
expect(turn.answer).toBe('Found it.')
expect(turn.tool_calls).toEqual([
{ name: 'get_order', args: { id: 1 }, result: '{"status":"shipped"}' }
])
})

it('leaves out the earlier turns a run with memory returns', () => {
const turn = readAgentTurn({
output: 'Refunded.',
messages: [
{ role: 'user', content: 'Where is my order?' },
{ role: 'assistant', tool_calls: [call('a', 'get_order', { id: 1 })] },
{ role: 'tool', tool_call_id: 'a', content: 'shipped' },
{ role: 'assistant', content: 'Found it.' },
{ role: 'user', content: 'Refund it.' },
{ role: 'assistant', tool_calls: [call('b', 'refund_order', { id: 1 })] },
{ role: 'tool', tool_call_id: 'b', content: 'ok' },
{ role: 'assistant', content: 'Refunded.' }
]
})
expect(turn.tool_calls.map((c) => c.name)).toEqual(['refund_order'])
})
})

describe('readAgentTurn with background tools', () => {
it('keeps a background call whose result came back as a tagged user message', () => {
const turn = readAgentTurn({
output: 'Rendered.',
messages: [
{ role: 'user', content: 'Render it.' },
{ role: 'assistant', tool_calls: [call('a', 'render', {})] },
{ role: 'tool', tool_call_id: 'a', content: 'Started in the background.' },
{
role: 'user',
content: 'Background tool `render` (call a, job j) finished. Result:\nok',
agent_action: { type: 'tool_call', job_id: 'j', function_name: 'render', module_id: 'm' }
},
{ role: 'assistant', content: 'Rendered.' }
]
})
expect(turn.tool_calls.map((c) => c.name)).toEqual(['render'])
})
})

describe('readAgentTurn with calls that are not tools of the agent', () => {
it('does not show the structured answer as a tool call', () => {
const turn = readAgentTurn({
output: { city: 'Paris' },
messages: [
{ role: 'user', content: 'Where?' },
{ role: 'assistant', tool_calls: [call('s', 'structured_output', { city: 'Paris' })] },
{ role: 'tool', tool_call_id: 's', content: 'Successfully ran structured_output tool' }
]
})
expect(turn.tool_calls).toEqual([])
expect(JSON.parse(turn.answer)).toEqual({ city: 'Paris' })
})

it('shows a web search, in the order it happened', () => {
const turn = readAgentTurn({
output: 'Found.',
messages: [
{ role: 'user', content: 'Look it up, then check the order.' },
{
role: 'tool',
content: 'Used websearch tool successfully',
agent_action: { type: 'web_search' }
},
{ role: 'assistant', tool_calls: [call('a', 'get_order', { id: 1 })] },
{ role: 'tool', tool_call_id: 'a', content: 'shipped' },
{ role: 'assistant', content: 'Found.' }
]
})
expect(turn.tool_calls.map((c) => c.name)).toEqual(['web_search', 'get_order'])
})
})
Loading
Loading