Skip to content

Commit 7a52743

Browse files
committed
fix: review comments
Signed-off-by: Jeff Napper <103025963+jnapper7@users.noreply.github.com>
1 parent f76d03a commit 7a52743

File tree

9 files changed

+113
-119
lines changed

9 files changed

+113
-119
lines changed

agntcy_acp/manifest/generator.py

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,28 @@
2020
)
2121

2222

23-
def _convert_descriptor_schema(schema_name, schema):
23+
def _convert_acp_spec_schema(schema_name, schema):
2424
return json.loads(
2525
json.dumps(schema).replace(
2626
"#/$defs/", f"#/components/schemas/{schema_name}/$defs/"
2727
)
2828
)
2929

3030

31-
def _gen_oas_thread_runs(descriptor: AgentACPSpec, spec_dict):
32-
# Manipulate the spec according to the thread capability flag in the descriptor
31+
def _gen_oas_thread_runs(acp_spec: AgentACPSpec, spec_dict):
32+
# Manipulate the spec according to the thread capability flag in the acp_spec
3333

34-
if descriptor.capabilities.threads:
35-
if descriptor.thread_state:
34+
if acp_spec.capabilities.threads:
35+
if acp_spec.thread_state:
3636
spec_dict["components"]["schemas"]["ThreadStateSchema"] = (
37-
_convert_descriptor_schema("ThreadStateSchema", descriptor.thread_state)
37+
_convert_acp_spec_schema("ThreadStateSchema", acp_spec.thread_state)
3838
)
3939
# else:
4040
# # No thread schema defined, hence no support to retrieve thread state
4141
# del spec_dict['paths']['/threads/{thread_id}/state']
4242
else:
4343
# Threads are not enabled
44-
if descriptor.thread_state:
44+
if acp_spec.thread_state:
4545
raise ACPDescriptorValidationException(
4646
"Cannot define `thread_state` if `capabilities.threads` is `false`"
4747
)
@@ -57,16 +57,16 @@ def _gen_oas_thread_runs(descriptor: AgentACPSpec, spec_dict):
5757
}
5858

5959

60-
def _gen_oas_interrupts(descriptor: AgentACPSpec, spec_dict):
61-
# Manipulate the spec according to the interrupts capability flag in the descriptor
60+
def _gen_oas_interrupts(acp_spec: AgentACPSpec, spec_dict):
61+
# Manipulate the spec according to the interrupts capability flag in the acp_spec
6262

63-
if descriptor.capabilities.interrupts:
64-
if not descriptor.interrupts or len(descriptor.interrupts) == 0:
63+
if acp_spec.capabilities.interrupts:
64+
if not acp_spec.interrupts or len(acp_spec.interrupts) == 0:
6565
raise ACPDescriptorValidationException(
6666
"Missing interrupt definitions with `spec.capabilities.interrupts=true`"
6767
)
6868

69-
# Add the interrupt payload and resume payload types for the schemas declared in the descriptor
69+
# Add the interrupt payload and resume payload types for the schemas declared in the acp_spec
7070
interrupt_payload_schema = spec_dict["components"]["schemas"][
7171
"InterruptPayloadSchema"
7272
] = {
@@ -77,7 +77,7 @@ def _gen_oas_interrupts(descriptor: AgentACPSpec, spec_dict):
7777
] = {
7878
"oneOf": [],
7979
}
80-
for interrupt in descriptor.interrupts:
80+
for interrupt in acp_spec.interrupts:
8181
interrupt_payload_schema_name = (
8282
f"{interrupt.interrupt_type}InterruptPayload"
8383
)
@@ -94,7 +94,7 @@ def _gen_oas_interrupts(descriptor: AgentACPSpec, spec_dict):
9494
}
9595
)
9696
spec_dict["components"]["schemas"][interrupt_payload_schema_name] = (
97-
_convert_descriptor_schema(
97+
_convert_acp_spec_schema(
9898
interrupt_payload_schema_name, interrupt.interrupt_payload
9999
)
100100
)
@@ -113,14 +113,14 @@ def _gen_oas_interrupts(descriptor: AgentACPSpec, spec_dict):
113113
}
114114
)
115115
spec_dict["components"]["schemas"][resume_payload_schema_name] = (
116-
_convert_descriptor_schema(
116+
_convert_acp_spec_schema(
117117
resume_payload_schema_name, interrupt.resume_payload
118118
)
119119
)
120120
else:
121121
# Interrupts are not supported
122122

123-
if descriptor.interrupts and len(descriptor.interrupts) > 0:
123+
if acp_spec.interrupts and len(acp_spec.interrupts) > 0:
124124
raise ACPDescriptorValidationException(
125125
"Interrupts defined with `spec.capabilities.interrupts=false`"
126126
)
@@ -140,28 +140,22 @@ def _gen_oas_interrupts(descriptor: AgentACPSpec, spec_dict):
140140
]
141141

142142

143-
def _gen_oas_streaming(descriptor: AgentACPSpec, spec_dict):
144-
# Manipulate the spec according to the streaming capability flag in the descriptor
143+
def _gen_oas_streaming(acp_spec: AgentACPSpec, spec_dict):
144+
# Manipulate the spec according to the streaming capability flag in the acp_spec
145145
streaming_modes = []
146-
if descriptor.capabilities.streaming:
147-
if descriptor.capabilities.streaming.custom:
146+
if acp_spec.capabilities.streaming:
147+
if acp_spec.capabilities.streaming.custom:
148148
streaming_modes.append(StreamingMode.CUSTOM)
149-
if descriptor.capabilities.streaming.values:
149+
if acp_spec.capabilities.streaming.values:
150150
streaming_modes.append(StreamingMode.VALUES)
151151

152152
# Perform the checks for custom_streaming_update
153-
if (
154-
StreamingMode.CUSTOM not in streaming_modes
155-
and descriptor.custom_streaming_update
156-
):
153+
if StreamingMode.CUSTOM not in streaming_modes and acp_spec.custom_streaming_update:
157154
raise ACPDescriptorValidationException(
158155
"custom_streaming_update defined with `spec.capabilities.streaming.custom=false`"
159156
)
160157

161-
if (
162-
StreamingMode.CUSTOM in streaming_modes
163-
and not descriptor.custom_streaming_update
164-
):
158+
if StreamingMode.CUSTOM in streaming_modes and not acp_spec.custom_streaming_update:
165159
raise ACPDescriptorValidationException(
166160
"Missing custom_streaming_update definitions with `spec.capabilities.streaming.custom=true`"
167161
)
@@ -195,9 +189,9 @@ def _gen_oas_streaming(descriptor: AgentACPSpec, spec_dict):
195189
]
196190

197191

198-
def _gen_oas_callback(descriptor: AgentACPSpec, spec_dict):
199-
# Manipulate the spec according to the callback capability flag in the descriptor
200-
if not descriptor.capabilities.callbacks:
192+
def _gen_oas_callback(acp_spec: AgentACPSpec, spec_dict):
193+
# Manipulate the spec according to the callback capability flag in the acp_spec
194+
if not acp_spec.capabilities.callbacks:
201195
# No streaming is supported. Removing callback option from RunCreate
202196
del spec_dict["components"]["schemas"]["RunCreate"]["properties"]["webhook"]
203197

@@ -209,13 +203,13 @@ def generate_agent_oapi_for_schemas(specs: AgentACPSpec):
209203
"components": {"schemas": {}},
210204
}
211205

212-
spec_dict["components"]["schemas"]["InputSchema"] = _convert_descriptor_schema(
206+
spec_dict["components"]["schemas"]["InputSchema"] = _convert_acp_spec_schema(
213207
"InputSchema", specs.input
214208
)
215-
spec_dict["components"]["schemas"]["OutputSchema"] = _convert_descriptor_schema(
209+
spec_dict["components"]["schemas"]["OutputSchema"] = _convert_acp_spec_schema(
216210
"OutputSchema", specs.output
217211
)
218-
spec_dict["components"]["schemas"]["ConfigSchema"] = _convert_descriptor_schema(
212+
spec_dict["components"]["schemas"]["ConfigSchema"] = _convert_acp_spec_schema(
219213
"ConfigSchema", specs.config
220214
)
221215

@@ -224,7 +218,7 @@ def generate_agent_oapi_for_schemas(specs: AgentACPSpec):
224218

225219

226220
def generate_agent_oapi(
227-
descriptor: Union[AgentACPDescriptor, AgentManifest],
221+
agent_source: Union[AgentACPDescriptor, AgentManifest],
228222
spec_path: Optional[str] = None,
229223
):
230224
if spec_path is None:
@@ -234,26 +228,26 @@ def generate_agent_oapi(
234228
validate(spec_dict)
235229

236230
agent_spec = None
237-
if isinstance(descriptor, AgentACPDescriptor):
238-
agent_spec = descriptor.specs
239-
agent_name = descriptor.metadata.ref.name
240-
elif isinstance(descriptor, AgentManifest):
241-
for ext in descriptor.extensions:
231+
if isinstance(agent_source, AgentACPDescriptor):
232+
agent_spec = agent_source.specs
233+
agent_name = agent_source.metadata.ref.name
234+
elif isinstance(agent_source, AgentManifest):
235+
for ext in agent_source.extensions:
242236
if ext.name == OASF_EXTENSION_NAME_MANIFEST:
243237
agent_spec = ext.data.acp
244-
agent_name = descriptor.name
238+
agent_name = agent_source.name
245239
else:
246-
raise ValueError("unknown object type for descriptor")
240+
raise ValueError("unknown object type for agent_source")
247241

248242
spec_dict["info"]["title"] = f"ACP Spec for {agent_name}"
249243

250-
spec_dict["components"]["schemas"]["InputSchema"] = _convert_descriptor_schema(
244+
spec_dict["components"]["schemas"]["InputSchema"] = _convert_acp_spec_schema(
251245
"InputSchema", agent_spec.input
252246
)
253-
spec_dict["components"]["schemas"]["OutputSchema"] = _convert_descriptor_schema(
247+
spec_dict["components"]["schemas"]["OutputSchema"] = _convert_acp_spec_schema(
254248
"OutputSchema", agent_spec.output
255249
)
256-
spec_dict["components"]["schemas"]["ConfigSchema"] = _convert_descriptor_schema(
250+
spec_dict["components"]["schemas"]["ConfigSchema"] = _convert_acp_spec_schema(
257251
"ConfigSchema", agent_spec.config
258252
)
259253

@@ -267,26 +261,26 @@ def generate_agent_oapi(
267261

268262

269263
def generate_agent_models(
270-
descriptor: Union[AgentACPDescriptor, AgentManifest],
264+
agent_source: Union[AgentACPDescriptor, AgentManifest],
271265
path: str,
272266
model_file_name: str = "models.py",
273267
):
274268
agent_spec = None
275-
if isinstance(descriptor, AgentACPDescriptor):
276-
agent_spec = generate_agent_oapi_for_schemas(descriptor.specs)
277-
agent_name = descriptor.metadata.ref.name
278-
elif isinstance(descriptor, AgentManifest):
279-
for ext in descriptor.extensions:
269+
if isinstance(agent_source, AgentACPDescriptor):
270+
agent_spec = generate_agent_oapi_for_schemas(agent_source.specs)
271+
agent_name = agent_source.metadata.ref.name
272+
elif isinstance(agent_source, AgentManifest):
273+
for ext in agent_source.extensions:
280274
if ext.name == OASF_EXTENSION_NAME_MANIFEST:
281275
agent_spec = generate_agent_oapi_for_schemas(ext.data.acp)
282-
agent_name = descriptor.name
276+
agent_name = agent_source.name
283277
else:
284-
raise ValueError("unknown object type for descriptor")
278+
raise ValueError("unknown object type for agent_source")
285279

286280
if agent_spec is None:
287-
raise ValueError("cannot find ACP descriptor")
281+
raise ValueError("cannot find agent data")
288282

289-
agent_sdk_path = path # os.path.join(path, f'{descriptor.metadata.ref.name}')
283+
agent_sdk_path = path
290284
agent_models_dir = agent_sdk_path
291285
tmp_dir = tempfile.TemporaryDirectory()
292286
specpath = os.path.join(tmp_dir.name, "openapi.yaml")

agntcy_acp/manifest/validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def validate_agent_descriptor_file(
2828
return validate_agent_descriptor(descriptor_json, raise_exception)
2929

3030

31-
def descriptor_from_manifest_obj(manifest: dict | AgentManifest) -> dict:
31+
def descriptor_from_manifest(manifest: dict | AgentManifest) -> dict:
3232
# ACP Descriptor is in the extensions of an Agent Manifest
3333
if hasattr(manifest, "extensions"):
3434
for ext in manifest.extensions:
@@ -49,7 +49,7 @@ def validate_agent_manifest(
4949
) -> AgentManifest | None:
5050
try:
5151
manifest = AgentManifest.model_validate(manifest_json)
52-
descriptor_json = descriptor_from_manifest_obj(manifest_json)
52+
descriptor_json = descriptor_from_manifest(manifest_json)
5353
validate_agent_descriptor(descriptor_json)
5454
# TODO: add additional manifest checks
5555
except (ValidationError, ACPDescriptorValidationException) as e:

0 commit comments

Comments
 (0)