Skip to content

Commit eef7eb0

Browse files
feat: add schema to agent (#2440)
--------- Co-authored-by: Brandon Kiser <[email protected]>
1 parent 8b88541 commit eef7eb0

File tree

5 files changed

+57
-19
lines changed

5 files changed

+57
-19
lines changed

crates/chat-cli/src/cli/agent/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ pub enum AgentConfigError {
120120
#[serde(rename_all = "camelCase", deny_unknown_fields)]
121121
#[schemars(description = "An Agent is a declarative way of configuring a given instance of q chat.")]
122122
pub struct Agent {
123+
#[serde(rename = "$schema", default = "default_schema")]
124+
pub schema: String,
123125
/// Name of the agent
124126
pub name: String,
125127
/// This field is not model facing and is mostly here for users to discern between agents
@@ -166,6 +168,7 @@ pub struct Agent {
166168
impl Default for Agent {
167169
fn default() -> Self {
168170
Self {
171+
schema: default_schema(),
169172
name: DEFAULT_AGENT_NAME.to_string(),
170173
description: Some("Default agent".to_string()),
171174
prompt: Default::default(),
@@ -766,6 +769,10 @@ async fn load_agents_from_entries(
766769
res
767770
}
768771

772+
fn default_schema() -> String {
773+
"https://raw.githubusercontent.com/aws/amazon-q-developer-cli/refs/heads/main/schemas/agent-v1.json".into()
774+
}
775+
769776
#[cfg(test)]
770777
fn validate_agent_name(name: &str) -> eyre::Result<()> {
771778
// Check if name is empty

crates/chat-cli/src/cli/agent/root_command_args.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,5 +368,15 @@ mod tests {
368368
})
369369
})
370370
);
371+
assert_parse!(
372+
["agent", "create", "-n", "some_agent", "--from", "some_old_agent"],
373+
RootSubcommand::Agent(AgentArgs {
374+
cmd: Some(AgentSubcommands::Create {
375+
name: "some_agent".to_string(),
376+
directory: None,
377+
from: Some("some_old_agent".to_string())
378+
})
379+
})
380+
);
371381
}
372382
}

crates/chat-cli/src/cli/mcp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ mod tests {
550550
}
551551

552552
#[test]
553-
fn test_mcp_subcomman_add() {
553+
fn test_mcp_subcommand_add() {
554554
assert_parse!(
555555
[
556556
"mcp",

docs/agent-format.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ The `name` field specifies the name of the agent. This is used for identificatio
2626
}
2727
```
2828

29-
Note: While this field can be included in the configuration file, it will be overridden by the filename when the agent is loaded.
30-
3129
## Description Field
3230

3331
The `description` field provides a description of what the agent does. This is primarily for human readability and helps users distinguish between different agents.

schemas/agent-v1.json

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33
"title": "Agent",
44
"description": "An Agent is a declarative way of configuring a given instance of q chat.",
55
"type": "object",
6+
"definitions": {
7+
"hookCommands": {
8+
"type": "array",
9+
"items": {
10+
"type": "object",
11+
"properties": {
12+
"command": {
13+
"description": "The command to run when the hook is triggered",
14+
"type": "string"
15+
}
16+
},
17+
"required": ["command"]
18+
}
19+
}
20+
},
621
"properties": {
722
"$schema": {
823
"description": "The schema to use for validating the agent",
@@ -14,12 +29,18 @@
1429
},
1530
"description": {
1631
"description": "This field is not model facing and is mostly here for users to discern between agents",
17-
"type": ["string", "null"],
32+
"type": [
33+
"string",
34+
"null"
35+
],
1836
"default": null
1937
},
2038
"prompt": {
2139
"description": "The intention for this field is to provide high level context to the\nagent. This should be seen as the same category of context as a system prompt.",
22-
"type": ["string", "null"],
40+
"type": [
41+
"string",
42+
"null"
43+
],
2344
"default": null
2445
},
2546
"mcpServers": {
@@ -42,7 +63,10 @@
4263
},
4364
"env": {
4465
"description": "A list of environment variables to run the command with",
45-
"type": ["object", "null"],
66+
"type": [
67+
"object",
68+
"null"
69+
],
4670
"additionalProperties": {
4771
"type": "string"
4872
}
@@ -60,7 +84,9 @@
6084
"default": false
6185
}
6286
},
63-
"required": ["command"]
87+
"required": [
88+
"command"
89+
]
6490
},
6591
"default": {}
6692
},
@@ -106,17 +132,12 @@
106132
"hooks": {
107133
"description": "Commands to run when a chat session is created",
108134
"type": "object",
109-
"additionalProperties": {
110-
"type": "array",
111-
"items": {
112-
"type": "object",
113-
"properties": {
114-
"command": {
115-
"description": "The command to run when the hook is triggered",
116-
"type": "string"
117-
}
118-
},
119-
"required": ["command"]
135+
"properties": {
136+
"userPromptSubmit": {
137+
"$ref": "#/definitions/hookCommands"
138+
},
139+
"agentSpawn": {
140+
"$ref": "#/definitions/hookCommands"
120141
}
121142
},
122143
"default": {}
@@ -141,5 +162,7 @@
141162
}
142163
},
143164
"additionalProperties": false,
144-
"required": ["name"]
165+
"required": [
166+
"name"
167+
]
145168
}

0 commit comments

Comments
 (0)