Skip to content

Commit 874c42f

Browse files
committed
refactor: move JSON schema to separate file
- Extract agent configuration schema to schemas/agent-config-v1.json - Add _load_schema() function to load schema from file at runtime - Improve code readability by separating schema from Python logic - Enable schema reuse by other tools and documentation - Maintain all existing validation functionality and tests 🤖 Assisted by Amazon Q Developer
1 parent 2f5d692 commit 874c42f

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

src/strands/experimental/agent_config.py

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,12 @@
1111

1212
from ..agent import Agent
1313

14-
# JSON Schema for agent configuration
15-
AGENT_CONFIG_SCHEMA = {
16-
"$schema": "http://json-schema.org/draft-07/schema#",
17-
"title": "Agent Configuration",
18-
"description": "Configuration schema for creating agents",
19-
"type": "object",
20-
"properties": {
21-
"name": {
22-
"description": "Name of the agent",
23-
"type": ["string", "null"],
24-
"default": None
25-
},
26-
"model": {
27-
"description": "The model ID to use for this agent. If not specified, uses the default model.",
28-
"type": ["string", "null"],
29-
"default": None
30-
},
31-
"prompt": {
32-
"description": "The system prompt for the agent. Provides high level context to the agent.",
33-
"type": ["string", "null"],
34-
"default": None
35-
},
36-
"tools": {
37-
"description": "List of tools the agent can use. Can be module paths, file paths, or tool names.",
38-
"type": "array",
39-
"items": {
40-
"type": "string"
41-
},
42-
"default": []
43-
}
44-
},
45-
"additionalProperties": False
46-
}
14+
15+
def _load_schema() -> dict:
16+
"""Load the agent configuration schema from file."""
17+
schema_path = Path(__file__).parent / "schemas" / "agent-config-v1.json"
18+
with open(schema_path, 'r') as f:
19+
return json.load(f)
4720

4821

4922
def config_to_agent(config: str | dict[str, any], **kwargs) -> Agent:
@@ -95,7 +68,8 @@ def config_to_agent(config: str | dict[str, any], **kwargs) -> Agent:
9568

9669
# Validate configuration against schema
9770
try:
98-
jsonschema.validate(config_dict, AGENT_CONFIG_SCHEMA)
71+
schema = _load_schema()
72+
jsonschema.validate(config_dict, schema)
9973
except ValidationError as e:
10074
# Provide more detailed error message
10175
error_path = " -> ".join(str(p) for p in e.absolute_path) if e.absolute_path else "root"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "Agent Configuration",
4+
"description": "Configuration schema for creating agents",
5+
"type": "object",
6+
"properties": {
7+
"name": {
8+
"description": "Name of the agent",
9+
"type": ["string", "null"],
10+
"default": null
11+
},
12+
"model": {
13+
"description": "The model ID to use for this agent. If not specified, uses the default model.",
14+
"type": ["string", "null"],
15+
"default": null
16+
},
17+
"prompt": {
18+
"description": "The system prompt for the agent. Provides high level context to the agent.",
19+
"type": ["string", "null"],
20+
"default": null
21+
},
22+
"tools": {
23+
"description": "List of tools the agent can use. Can be module paths, file paths, or tool names.",
24+
"type": "array",
25+
"items": {
26+
"type": "string"
27+
},
28+
"default": []
29+
}
30+
},
31+
"additionalProperties": false
32+
}

0 commit comments

Comments
 (0)