agent-framework-devui 1.0.0b260821__tar.gz → 1.0.0b260910__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/PKG-INFO +4 -4
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/_conversations.py +176 -35
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/_executor.py +126 -65
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/_mapper.py +181 -81
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/_openai/__init__.py +9 -9
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/_server.py +3 -27
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/_utils.py +29 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/models/__init__.py +98 -94
- agent_framework_devui-1.0.0b260910/agent_framework_devui/ui/assets/index.js +193 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/pyproject.toml +5 -5
- agent_framework_devui-1.0.0b260821/agent_framework_devui/ui/assets/index.js +0 -199
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/LICENSE +0 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/README.md +0 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/__init__.py +0 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/_cli.py +0 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/_deployment.py +0 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/_discovery.py +0 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/_feature_usage.py +0 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/_openai/_executor.py +0 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/_session.py +0 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/_tracing.py +0 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/models/_discovery_models.py +0 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/models/_openai_custom.py +0 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/ui/agentframework.svg +0 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/ui/assets/index.css +0 -0
- {agent_framework_devui-1.0.0b260821 → agent_framework_devui-1.0.0b260910}/agent_framework_devui/ui/index.html +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: agent-framework-devui
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.0b260910
|
|
4
4
|
Summary: Debug UI for Microsoft Agent Framework with OpenAI-compatible API server.
|
|
5
5
|
Author-email: Microsoft <af-support@microsoft.com>
|
|
6
6
|
Requires-Python: >=3.10
|
|
@@ -16,10 +16,10 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.14
|
|
17
17
|
Classifier: Typing :: Typed
|
|
18
18
|
License-File: LICENSE
|
|
19
|
-
Requires-Dist: agent-framework-core>=1.
|
|
20
|
-
Requires-Dist: openai>=2.45.0,<
|
|
19
|
+
Requires-Dist: agent-framework-core>=1.17.0,<2
|
|
20
|
+
Requires-Dist: openai>=2.45.0,<4
|
|
21
21
|
Requires-Dist: opentelemetry-sdk>=1.39.0,<2
|
|
22
|
-
Requires-Dist: fastapi>=0.115.0,<0.
|
|
22
|
+
Requires-Dist: fastapi>=0.115.0,<0.142.0
|
|
23
23
|
Requires-Dist: uvicorn[standard]>=0.30.0,<1
|
|
24
24
|
Requires-Dist: pytest==9.1.1 ; extra == "all"
|
|
25
25
|
Requires-Dist: watchdog==6.0.0 ; extra == "all"
|
|
@@ -14,7 +14,7 @@ from abc import ABC, abstractmethod
|
|
|
14
14
|
from collections.abc import MutableSequence
|
|
15
15
|
from typing import Any, Literal, cast
|
|
16
16
|
|
|
17
|
-
from agent_framework import AgentSession, Message
|
|
17
|
+
from agent_framework import AgentSession, Content, Message
|
|
18
18
|
from agent_framework._workflows._checkpoint import InMemoryCheckpointStorage, WorkflowCheckpoint
|
|
19
19
|
from openai.types.conversations import Conversation, ConversationDeletedResource
|
|
20
20
|
from openai.types.conversations.conversation_item import ConversationItem
|
|
@@ -26,8 +26,14 @@ from openai.types.responses import (
|
|
|
26
26
|
ResponseFunctionToolCallOutputItem,
|
|
27
27
|
ResponseInputFile,
|
|
28
28
|
ResponseInputImage,
|
|
29
|
+
ResponseOutputRefusal,
|
|
29
30
|
)
|
|
30
31
|
|
|
32
|
+
from ._utils import infer_media_type
|
|
33
|
+
|
|
34
|
+
_MODEL_OUTPUT_KIND_KEY = "model_output_kind"
|
|
35
|
+
_MODEL_OUTPUT_REFUSAL = "refusal"
|
|
36
|
+
|
|
31
37
|
# Type alias for OpenAI Message role literals
|
|
32
38
|
MessageRole = Literal["unknown", "user", "assistant", "system", "critic", "discriminator", "developer", "tool"]
|
|
33
39
|
|
|
@@ -304,17 +310,23 @@ class InMemoryConversationStore(ConversationStore):
|
|
|
304
310
|
# Convert items to Messages and add to storage
|
|
305
311
|
chat_messages: list[Message] = []
|
|
306
312
|
for item in items:
|
|
307
|
-
# Simple conversion - assume text content for now
|
|
308
313
|
role = item.get("role", "user")
|
|
309
314
|
content = item.get("content", [])
|
|
310
|
-
|
|
311
|
-
dict[str, Any],
|
|
312
|
-
content[0] if content and isinstance(content, list) and isinstance(content[0], dict) else {},
|
|
313
|
-
)
|
|
314
|
-
text_obj = first_content.get("text", "")
|
|
315
|
-
text = text_obj if isinstance(text_obj, str) else str(text_obj)
|
|
315
|
+
contents: list[Content] = []
|
|
316
316
|
|
|
317
|
-
|
|
317
|
+
if isinstance(content, str):
|
|
318
|
+
contents.append(Content.from_text(text=content))
|
|
319
|
+
elif isinstance(content, list):
|
|
320
|
+
for content_item in cast(list[object], content):
|
|
321
|
+
if isinstance(content_item, dict):
|
|
322
|
+
agent_content = self._to_agent_content(cast(dict[str, Any], content_item))
|
|
323
|
+
if agent_content is not None:
|
|
324
|
+
contents.append(agent_content)
|
|
325
|
+
|
|
326
|
+
if not contents:
|
|
327
|
+
raise ValueError("Conversation message did not contain any supported content")
|
|
328
|
+
|
|
329
|
+
chat_msg = Message(role=role, contents=contents)
|
|
318
330
|
chat_messages.append(chat_msg)
|
|
319
331
|
|
|
320
332
|
# Add messages to internal storage
|
|
@@ -328,9 +340,9 @@ class InMemoryConversationStore(ConversationStore):
|
|
|
328
340
|
# Convert Message contents to OpenAI TextContent format
|
|
329
341
|
message_content: MutableSequence[OpenAIContent] = []
|
|
330
342
|
for content_item in msg.contents:
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
message_content.append(
|
|
343
|
+
openai_content = self._to_openai_content(content_item)
|
|
344
|
+
if openai_content is not None:
|
|
345
|
+
message_content.append(openai_content)
|
|
334
346
|
|
|
335
347
|
# Create Message object (concrete type from ConversationItem union)
|
|
336
348
|
message = OpenAIMessage(
|
|
@@ -384,35 +396,16 @@ class InMemoryConversationStore(ConversationStore):
|
|
|
384
396
|
# Process each content item in the message
|
|
385
397
|
# A single Message may produce multiple ConversationItems
|
|
386
398
|
# (e.g., a message with both text and a function call)
|
|
387
|
-
message_contents: list[TextContent | ResponseInputImage | ResponseInputFile] = []
|
|
399
|
+
message_contents: list[TextContent | ResponseOutputRefusal | ResponseInputImage | ResponseInputFile] = []
|
|
388
400
|
function_calls: list[ResponseFunctionToolCallItem] = []
|
|
389
401
|
function_results: list[ResponseFunctionToolCallOutputItem] = []
|
|
390
402
|
|
|
391
403
|
for content in msg.contents:
|
|
392
404
|
content_type = getattr(content, "type", None)
|
|
405
|
+
mapped_content = self._to_openai_content(content)
|
|
393
406
|
|
|
394
|
-
if
|
|
395
|
-
|
|
396
|
-
text_value = getattr(content, "text", "")
|
|
397
|
-
message_contents.append(TextContent(type="text", text=text_value))
|
|
398
|
-
|
|
399
|
-
elif content_type == "data":
|
|
400
|
-
# Data content (images, files, PDFs)
|
|
401
|
-
uri = getattr(content, "uri", "")
|
|
402
|
-
media_type = getattr(content, "media_type", None)
|
|
403
|
-
|
|
404
|
-
if media_type and media_type.startswith("image/"):
|
|
405
|
-
# Convert to ResponseInputImage
|
|
406
|
-
message_contents.append(ResponseInputImage(type="input_image", image_url=uri, detail="auto"))
|
|
407
|
-
else:
|
|
408
|
-
# Convert to ResponseInputFile
|
|
409
|
-
# Extract filename from URI if possible
|
|
410
|
-
filename = None
|
|
411
|
-
if media_type == "application/pdf":
|
|
412
|
-
filename = "document.pdf"
|
|
413
|
-
|
|
414
|
-
message_contents.append(ResponseInputFile(type="input_file", file_url=uri, filename=filename))
|
|
415
|
-
|
|
407
|
+
if mapped_content is not None:
|
|
408
|
+
message_contents.append(mapped_content)
|
|
416
409
|
elif content_type == "function_call":
|
|
417
410
|
# Function call - create separate ConversationItem
|
|
418
411
|
call_id = getattr(content, "call_id", None)
|
|
@@ -532,6 +525,154 @@ class InMemoryConversationStore(ConversationStore):
|
|
|
532
525
|
|
|
533
526
|
return paginated_items, has_more
|
|
534
527
|
|
|
528
|
+
@staticmethod
|
|
529
|
+
def _to_agent_content(content: dict[str, Any]) -> Content | None:
|
|
530
|
+
"""Convert one supported OpenAI conversation message part."""
|
|
531
|
+
content_type = content.get("type")
|
|
532
|
+
if content_type in ("text", "input_text", "output_text"):
|
|
533
|
+
text = content.get("text")
|
|
534
|
+
return Content.from_text(text=text) if isinstance(text, str) else None
|
|
535
|
+
|
|
536
|
+
if content_type == "refusal":
|
|
537
|
+
refusal = content.get("refusal")
|
|
538
|
+
if not isinstance(refusal, str):
|
|
539
|
+
return None
|
|
540
|
+
return Content.from_text(
|
|
541
|
+
text=refusal,
|
|
542
|
+
additional_properties={_MODEL_OUTPUT_KIND_KEY: _MODEL_OUTPUT_REFUSAL},
|
|
543
|
+
)
|
|
544
|
+
|
|
545
|
+
if content_type == "input_image":
|
|
546
|
+
detail = content.get("detail", "auto")
|
|
547
|
+
image_properties = {
|
|
548
|
+
"openai_content_type": "input_image",
|
|
549
|
+
"detail": detail if isinstance(detail, str) else "auto",
|
|
550
|
+
}
|
|
551
|
+
image_url = content.get("image_url")
|
|
552
|
+
if isinstance(image_url, str) and image_url:
|
|
553
|
+
return Content.from_uri(
|
|
554
|
+
uri=image_url,
|
|
555
|
+
media_type=infer_media_type(uri=image_url, default="image/png"),
|
|
556
|
+
additional_properties=image_properties,
|
|
557
|
+
)
|
|
558
|
+
file_id = content.get("file_id")
|
|
559
|
+
if isinstance(file_id, str) and file_id:
|
|
560
|
+
return Content.from_hosted_file(
|
|
561
|
+
file_id=file_id,
|
|
562
|
+
additional_properties=image_properties,
|
|
563
|
+
)
|
|
564
|
+
return None
|
|
565
|
+
|
|
566
|
+
if content_type == "input_file":
|
|
567
|
+
filename = content.get("filename")
|
|
568
|
+
filename = filename if isinstance(filename, str) else ""
|
|
569
|
+
detail = content.get("detail")
|
|
570
|
+
file_properties: dict[str, Any] = {"openai_content_type": "input_file"}
|
|
571
|
+
if filename:
|
|
572
|
+
file_properties["filename"] = filename
|
|
573
|
+
if isinstance(detail, str):
|
|
574
|
+
file_properties["detail"] = detail
|
|
575
|
+
|
|
576
|
+
file_data = content.get("file_data")
|
|
577
|
+
if isinstance(file_data, str) and file_data:
|
|
578
|
+
media_type = infer_media_type(
|
|
579
|
+
filename=filename,
|
|
580
|
+
uri=file_data,
|
|
581
|
+
default="application/octet-stream",
|
|
582
|
+
)
|
|
583
|
+
uri = file_data if file_data.startswith("data:") else f"data:{media_type};base64,{file_data}"
|
|
584
|
+
return Content.from_uri(
|
|
585
|
+
uri=uri,
|
|
586
|
+
media_type=media_type,
|
|
587
|
+
additional_properties=file_properties,
|
|
588
|
+
)
|
|
589
|
+
|
|
590
|
+
file_url = content.get("file_url")
|
|
591
|
+
if isinstance(file_url, str) and file_url:
|
|
592
|
+
return Content.from_uri(
|
|
593
|
+
uri=file_url,
|
|
594
|
+
media_type=infer_media_type(
|
|
595
|
+
filename=filename,
|
|
596
|
+
uri=file_url,
|
|
597
|
+
default="application/octet-stream",
|
|
598
|
+
),
|
|
599
|
+
additional_properties=file_properties,
|
|
600
|
+
)
|
|
601
|
+
|
|
602
|
+
file_id = content.get("file_id")
|
|
603
|
+
if isinstance(file_id, str) and file_id:
|
|
604
|
+
return Content.from_hosted_file(
|
|
605
|
+
file_id=file_id,
|
|
606
|
+
media_type=infer_media_type(filename=filename, default="application/octet-stream"),
|
|
607
|
+
name=filename or None,
|
|
608
|
+
additional_properties=file_properties,
|
|
609
|
+
)
|
|
610
|
+
|
|
611
|
+
return None
|
|
612
|
+
|
|
613
|
+
@staticmethod
|
|
614
|
+
def _to_openai_content(
|
|
615
|
+
content: Content,
|
|
616
|
+
) -> TextContent | ResponseOutputRefusal | ResponseInputImage | ResponseInputFile | None:
|
|
617
|
+
"""Convert one supported Agent Framework message part."""
|
|
618
|
+
content_type = content.type
|
|
619
|
+
if content_type == "text":
|
|
620
|
+
if content.additional_properties.get(_MODEL_OUTPUT_KIND_KEY) == _MODEL_OUTPUT_REFUSAL:
|
|
621
|
+
return ResponseOutputRefusal(type="refusal", refusal=content.text or "")
|
|
622
|
+
return TextContent(type="text", text=content.text or "")
|
|
623
|
+
|
|
624
|
+
additional_properties = content.additional_properties or {}
|
|
625
|
+
openai_content_type = additional_properties.get("openai_content_type")
|
|
626
|
+
is_image = openai_content_type == "input_image" or (
|
|
627
|
+
openai_content_type is None and bool(content.media_type and content.media_type.startswith("image/"))
|
|
628
|
+
)
|
|
629
|
+
|
|
630
|
+
if content_type in ("data", "uri"):
|
|
631
|
+
if is_image:
|
|
632
|
+
detail = additional_properties.get("detail", "auto")
|
|
633
|
+
if detail not in ("low", "high", "auto", "original"):
|
|
634
|
+
detail = "auto"
|
|
635
|
+
return ResponseInputImage(
|
|
636
|
+
type="input_image",
|
|
637
|
+
image_url=content.uri,
|
|
638
|
+
detail=detail,
|
|
639
|
+
)
|
|
640
|
+
|
|
641
|
+
filename = additional_properties.get("filename")
|
|
642
|
+
detail = additional_properties.get("detail")
|
|
643
|
+
if detail not in ("low", "high", "auto"):
|
|
644
|
+
detail = None
|
|
645
|
+
return ResponseInputFile(
|
|
646
|
+
type="input_file",
|
|
647
|
+
file_url=content.uri,
|
|
648
|
+
filename=filename if isinstance(filename, str) else None,
|
|
649
|
+
detail=detail,
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
if content_type == "hosted_file":
|
|
653
|
+
if is_image:
|
|
654
|
+
detail = additional_properties.get("detail", "auto")
|
|
655
|
+
if detail not in ("low", "high", "auto", "original"):
|
|
656
|
+
detail = "auto"
|
|
657
|
+
return ResponseInputImage(
|
|
658
|
+
type="input_image",
|
|
659
|
+
file_id=content.file_id,
|
|
660
|
+
detail=detail,
|
|
661
|
+
)
|
|
662
|
+
|
|
663
|
+
filename = content.name or additional_properties.get("filename")
|
|
664
|
+
detail = additional_properties.get("detail")
|
|
665
|
+
if detail not in ("low", "high", "auto"):
|
|
666
|
+
detail = None
|
|
667
|
+
return ResponseInputFile(
|
|
668
|
+
type="input_file",
|
|
669
|
+
file_id=content.file_id,
|
|
670
|
+
filename=filename if isinstance(filename, str) else None,
|
|
671
|
+
detail=detail,
|
|
672
|
+
)
|
|
673
|
+
|
|
674
|
+
return None
|
|
675
|
+
|
|
535
676
|
async def get_item(self, conversation_id: str, item_id: str) -> ConversationItem | None:
|
|
536
677
|
"""Get a specific conversation item by ID.
|
|
537
678
|
|
|
@@ -15,11 +15,14 @@ from ._conversations import ConversationStore, InMemoryConversationStore
|
|
|
15
15
|
from ._discovery import EntityDiscovery
|
|
16
16
|
from ._mapper import MessageMapper
|
|
17
17
|
from ._tracing import capture_traces
|
|
18
|
+
from ._utils import infer_media_type
|
|
18
19
|
from .models import AgentFrameworkRequest, OpenAIResponse
|
|
19
20
|
from .models._discovery_models import EntityInfo
|
|
20
21
|
|
|
21
22
|
logger = logging.getLogger(__name__)
|
|
22
23
|
|
|
24
|
+
_OPENAI_MESSAGE_ROLES = {"user", "assistant", "system", "developer"}
|
|
25
|
+
|
|
23
26
|
|
|
24
27
|
def _get_event_type(event: Any) -> str | None:
|
|
25
28
|
"""Safely get the type of an event, handling both objects and dicts."""
|
|
@@ -35,6 +38,10 @@ class EntityNotFoundError(Exception):
|
|
|
35
38
|
pass
|
|
36
39
|
|
|
37
40
|
|
|
41
|
+
class InputConversionError(ValueError):
|
|
42
|
+
"""Raised when OpenAI input contains no supported Agent Framework content."""
|
|
43
|
+
|
|
44
|
+
|
|
38
45
|
class AgentFrameworkExecutor:
|
|
39
46
|
"""Executor for Agent Framework entities - agents and workflows."""
|
|
40
47
|
|
|
@@ -128,7 +135,9 @@ class AgentFrameworkExecutor:
|
|
|
128
135
|
request_id = event.get("request_id")
|
|
129
136
|
fc = event.get("function_call", {})
|
|
130
137
|
if isinstance(request_id, str) and request_id:
|
|
138
|
+
occurrence_id = fc.get("occurrence_id")
|
|
131
139
|
self._pending_approvals[request_id] = {
|
|
140
|
+
"id": occurrence_id if isinstance(occurrence_id, str) and occurrence_id else request_id,
|
|
132
141
|
"call_id": fc.get("id", ""),
|
|
133
142
|
"name": fc.get("name", ""),
|
|
134
143
|
"arguments": fc.get("arguments", {}),
|
|
@@ -229,6 +238,7 @@ class AgentFrameworkExecutor:
|
|
|
229
238
|
OpenAI response stream events
|
|
230
239
|
"""
|
|
231
240
|
try:
|
|
241
|
+
events: list[Any] = []
|
|
232
242
|
entity_id = request.get_entity_id()
|
|
233
243
|
if not entity_id:
|
|
234
244
|
logger.error("No entity_id specified in request")
|
|
@@ -249,8 +259,13 @@ class AgentFrameworkExecutor:
|
|
|
249
259
|
and cast(dict[str, Any], event).get("type") == "response.function_approval.requested"
|
|
250
260
|
):
|
|
251
261
|
self._track_approval_request(cast(dict[str, Any], event))
|
|
262
|
+
events.append(event)
|
|
263
|
+
if _get_event_type(event) == "response.failed":
|
|
264
|
+
continue
|
|
252
265
|
yield event
|
|
253
266
|
|
|
267
|
+
yield await self.message_mapper.finalize_stream(events, request)
|
|
268
|
+
|
|
254
269
|
except Exception as e:
|
|
255
270
|
logger.exception(f"Error in streaming execution: {e}")
|
|
256
271
|
# Could yield error event here
|
|
@@ -267,7 +282,14 @@ class AgentFrameworkExecutor:
|
|
|
267
282
|
# Collect all streaming events
|
|
268
283
|
events = [event async for event in self.execute_streaming(request)]
|
|
269
284
|
|
|
270
|
-
|
|
285
|
+
for event in reversed(events):
|
|
286
|
+
if _get_event_type(event) not in ("response.completed", "response.failed"):
|
|
287
|
+
continue
|
|
288
|
+
response = getattr(event, "response", None)
|
|
289
|
+
if isinstance(response, OpenAIResponse):
|
|
290
|
+
return response
|
|
291
|
+
|
|
292
|
+
# Preserve the existing empty-response fallback when execution produced no events.
|
|
271
293
|
return await self.message_mapper.aggregate_to_response(events, request)
|
|
272
294
|
|
|
273
295
|
async def execute_entity(self, entity_id: str, request: AgentFrameworkRequest) -> AsyncGenerator[Any]:
|
|
@@ -592,6 +614,10 @@ class AgentFrameworkExecutor:
|
|
|
592
614
|
# The workflow is already paused by ctx.request_info() in the framework
|
|
593
615
|
# DevUI should continue yielding events even during HIL pause
|
|
594
616
|
|
|
617
|
+
except InputConversionError as e:
|
|
618
|
+
from .models._openai_custom import AgentFailedEvent
|
|
619
|
+
|
|
620
|
+
yield AgentFailedEvent(error=e)
|
|
595
621
|
except Exception as e:
|
|
596
622
|
logger.error(f"Error in workflow execution: {e}")
|
|
597
623
|
yield {"type": "error", "message": f"Workflow execution error: {e!s}"}
|
|
@@ -610,7 +636,7 @@ class AgentFrameworkExecutor:
|
|
|
610
636
|
"""
|
|
611
637
|
# Import Agent Framework types
|
|
612
638
|
try:
|
|
613
|
-
from agent_framework import Message
|
|
639
|
+
from agent_framework import Message
|
|
614
640
|
except ImportError:
|
|
615
641
|
# Fallback to string extraction if Agent Framework not available
|
|
616
642
|
return self._extract_user_message_fallback(input_data)
|
|
@@ -622,13 +648,13 @@ class AgentFrameworkExecutor:
|
|
|
622
648
|
# Handle OpenAI ResponseInputParam (List[ResponseInputItemParam])
|
|
623
649
|
if isinstance(input_data, list):
|
|
624
650
|
input_items: Any = cast(Any, input_data)
|
|
625
|
-
return self._convert_openai_input_to_chat_message(input_items, Message
|
|
651
|
+
return self._convert_openai_input_to_chat_message(input_items, Message)
|
|
626
652
|
|
|
627
653
|
# Fallback for other formats
|
|
628
654
|
return self._extract_user_message_fallback(input_data)
|
|
629
655
|
|
|
630
|
-
def _convert_openai_input_to_chat_message(self, input_items: list[Any], Message: Any
|
|
631
|
-
"""Convert OpenAI ResponseInputParam to Agent Framework
|
|
656
|
+
def _convert_openai_input_to_chat_message(self, input_items: list[Any], Message: Any) -> Any:
|
|
657
|
+
"""Convert OpenAI ResponseInputParam to Agent Framework messages.
|
|
632
658
|
|
|
633
659
|
Processes text, images, files, and other content types from OpenAI format
|
|
634
660
|
to Agent Framework Message with appropriate content objects.
|
|
@@ -636,12 +662,12 @@ class AgentFrameworkExecutor:
|
|
|
636
662
|
Args:
|
|
637
663
|
input_items: List of OpenAI ResponseInputItemParam objects (dicts or objects)
|
|
638
664
|
Message: Message class for creating chat messages
|
|
639
|
-
Role: Role enum for message roles
|
|
640
665
|
|
|
641
666
|
Returns:
|
|
642
|
-
Message
|
|
667
|
+
One Message, or a list of Messages when input contains multiple message items
|
|
643
668
|
"""
|
|
644
|
-
|
|
669
|
+
messages: list[Any] = []
|
|
670
|
+
approval_request_ids: set[str] = set()
|
|
645
671
|
|
|
646
672
|
# Process each input item
|
|
647
673
|
for item in input_items:
|
|
@@ -649,9 +675,15 @@ class AgentFrameworkExecutor:
|
|
|
649
675
|
if isinstance(item, dict):
|
|
650
676
|
item_dict = cast(dict[str, Any], item)
|
|
651
677
|
item_type = item_dict.get("type")
|
|
652
|
-
|
|
678
|
+
is_easy_message = item_type is None and "role" in item_dict and "content" in item_dict
|
|
679
|
+
if item_type == "message" or is_easy_message:
|
|
680
|
+
role_value = item_dict.get("role", "user")
|
|
681
|
+
if not isinstance(role_value, str) or role_value not in _OPENAI_MESSAGE_ROLES:
|
|
682
|
+
raise InputConversionError(f"Unsupported OpenAI input message role: {role_value!r}")
|
|
683
|
+
|
|
653
684
|
# Extract content from OpenAI message
|
|
654
685
|
message_content = item_dict.get("content", [])
|
|
686
|
+
contents: list[Content] = []
|
|
655
687
|
|
|
656
688
|
# Handle both string content and list content
|
|
657
689
|
if isinstance(message_content, str):
|
|
@@ -664,78 +696,97 @@ class AgentFrameworkExecutor:
|
|
|
664
696
|
content_dict = cast(dict[str, Any], content_item)
|
|
665
697
|
content_type = content_dict.get("type")
|
|
666
698
|
|
|
667
|
-
if content_type
|
|
699
|
+
if content_type in ("input_text", "output_text", "text"):
|
|
668
700
|
text = content_dict.get("text", "")
|
|
669
701
|
if isinstance(text, str):
|
|
670
702
|
contents.append(Content.from_text(text=text))
|
|
671
703
|
|
|
672
704
|
elif content_type == "input_image":
|
|
673
705
|
image_url = content_dict.get("image_url", "")
|
|
706
|
+
file_id = content_dict.get("file_id")
|
|
707
|
+
detail = content_dict.get("detail", "auto")
|
|
708
|
+
image_properties = {
|
|
709
|
+
"openai_content_type": "input_image",
|
|
710
|
+
"detail": detail if isinstance(detail, str) else "auto",
|
|
711
|
+
}
|
|
674
712
|
if isinstance(image_url, str) and image_url:
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
713
|
+
media_type = infer_media_type(uri=image_url, default="image/png")
|
|
714
|
+
contents.append(
|
|
715
|
+
Content.from_uri(
|
|
716
|
+
uri=image_url,
|
|
717
|
+
media_type=media_type,
|
|
718
|
+
additional_properties=image_properties,
|
|
719
|
+
)
|
|
720
|
+
)
|
|
721
|
+
elif isinstance(file_id, str) and file_id:
|
|
722
|
+
contents.append(
|
|
723
|
+
Content.from_hosted_file(
|
|
724
|
+
file_id=file_id,
|
|
725
|
+
additional_properties=image_properties,
|
|
726
|
+
)
|
|
727
|
+
)
|
|
689
728
|
|
|
690
729
|
elif content_type == "input_file":
|
|
691
730
|
# Handle file input
|
|
692
731
|
file_data = content_dict.get("file_data")
|
|
732
|
+
file_id = content_dict.get("file_id")
|
|
693
733
|
file_url = content_dict.get("file_url")
|
|
694
734
|
filename = content_dict.get("filename", "")
|
|
735
|
+
detail = content_dict.get("detail")
|
|
695
736
|
|
|
696
737
|
if not isinstance(filename, str):
|
|
697
738
|
filename = ""
|
|
698
739
|
|
|
699
|
-
# Determine media type from filename
|
|
700
|
-
media_type = "application/octet-stream" # default
|
|
701
|
-
if filename:
|
|
702
|
-
if filename.lower().endswith(".pdf"):
|
|
703
|
-
media_type = "application/pdf"
|
|
704
|
-
elif filename.lower().endswith((".png", ".jpg", ".jpeg", ".gif")):
|
|
705
|
-
media_type = f"image/{filename.split('.')[-1].lower()}"
|
|
706
|
-
elif filename.lower().endswith((
|
|
707
|
-
".wav",
|
|
708
|
-
".mp3",
|
|
709
|
-
".m4a",
|
|
710
|
-
".ogg",
|
|
711
|
-
".flac",
|
|
712
|
-
".aac",
|
|
713
|
-
)):
|
|
714
|
-
ext = filename.split(".")[-1].lower()
|
|
715
|
-
# Normalize extensions to match audio MIME types
|
|
716
|
-
media_type = "audio/mp4" if ext == "m4a" else f"audio/{ext}"
|
|
717
|
-
|
|
718
740
|
# Use file_data or file_url
|
|
719
741
|
# Include filename in additional_properties for OpenAI/Azure file handling
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
742
|
+
file_properties: dict[str, Any] = {"openai_content_type": "input_file"}
|
|
743
|
+
if filename:
|
|
744
|
+
file_properties["filename"] = filename
|
|
745
|
+
if isinstance(detail, str):
|
|
746
|
+
file_properties["detail"] = detail
|
|
747
|
+
|
|
723
748
|
if isinstance(file_data, str) and file_data:
|
|
724
|
-
|
|
725
|
-
|
|
749
|
+
media_type = infer_media_type(
|
|
750
|
+
filename=filename,
|
|
751
|
+
uri=file_data,
|
|
752
|
+
default="application/octet-stream",
|
|
753
|
+
)
|
|
754
|
+
data_uri = (
|
|
755
|
+
file_data
|
|
756
|
+
if file_data.startswith("data:")
|
|
757
|
+
else f"data:{media_type};base64,{file_data}"
|
|
758
|
+
)
|
|
726
759
|
contents.append(
|
|
727
760
|
Content.from_uri(
|
|
728
761
|
uri=data_uri,
|
|
729
762
|
media_type=media_type,
|
|
730
|
-
additional_properties=
|
|
763
|
+
additional_properties=file_properties,
|
|
731
764
|
)
|
|
732
765
|
)
|
|
733
766
|
elif isinstance(file_url, str) and file_url:
|
|
767
|
+
media_type = infer_media_type(
|
|
768
|
+
filename=filename,
|
|
769
|
+
uri=file_url,
|
|
770
|
+
default="application/octet-stream",
|
|
771
|
+
)
|
|
734
772
|
contents.append(
|
|
735
773
|
Content.from_uri(
|
|
736
774
|
uri=file_url,
|
|
737
775
|
media_type=media_type,
|
|
738
|
-
additional_properties=
|
|
776
|
+
additional_properties=file_properties,
|
|
777
|
+
)
|
|
778
|
+
)
|
|
779
|
+
elif isinstance(file_id, str) and file_id:
|
|
780
|
+
media_type = infer_media_type(
|
|
781
|
+
filename=filename,
|
|
782
|
+
default="application/octet-stream",
|
|
783
|
+
)
|
|
784
|
+
contents.append(
|
|
785
|
+
Content.from_hosted_file(
|
|
786
|
+
file_id=file_id,
|
|
787
|
+
media_type=media_type,
|
|
788
|
+
name=filename or None,
|
|
789
|
+
additional_properties=file_properties,
|
|
739
790
|
)
|
|
740
791
|
)
|
|
741
792
|
|
|
@@ -752,7 +803,11 @@ class AgentFrameworkExecutor:
|
|
|
752
803
|
|
|
753
804
|
# Only accept responses that match a request we issued.
|
|
754
805
|
# Always use the server-stored function_call data.
|
|
755
|
-
stored_fc =
|
|
806
|
+
stored_fc = (
|
|
807
|
+
None
|
|
808
|
+
if request_id in approval_request_ids
|
|
809
|
+
else self._pending_approvals.get(request_id)
|
|
810
|
+
)
|
|
756
811
|
if stored_fc is None:
|
|
757
812
|
logger.warning(
|
|
758
813
|
"Rejected function_approval_response with unknown "
|
|
@@ -777,6 +832,7 @@ class AgentFrameworkExecutor:
|
|
|
777
832
|
name=stored_fc["name"],
|
|
778
833
|
arguments=stored_fc["arguments"],
|
|
779
834
|
)
|
|
835
|
+
function_call.id = stored_fc.get("id", request_id)
|
|
780
836
|
|
|
781
837
|
# Create approval response using server-validated data
|
|
782
838
|
approval_response = Content.from_function_approval_response(
|
|
@@ -786,6 +842,7 @@ class AgentFrameworkExecutor:
|
|
|
786
842
|
additional_properties=approval_additional_props,
|
|
787
843
|
)
|
|
788
844
|
contents.append(approval_response)
|
|
845
|
+
approval_request_ids.add(request_id)
|
|
789
846
|
logger.info(
|
|
790
847
|
"Validated FunctionApprovalResponseContent: id=%s, "
|
|
791
848
|
"approved=%s, function=%s, policy_violation=%s",
|
|
@@ -801,24 +858,23 @@ class AgentFrameworkExecutor:
|
|
|
801
858
|
except Exception as e:
|
|
802
859
|
logger.error(f"Failed to process FunctionApprovalResponseContent: {e}")
|
|
803
860
|
|
|
861
|
+
if not contents:
|
|
862
|
+
raise InputConversionError("OpenAI input message did not contain any supported message content")
|
|
863
|
+
|
|
864
|
+
messages.append(Message(role=role_value, contents=contents))
|
|
865
|
+
|
|
804
866
|
# Handle other OpenAI input item types as needed
|
|
805
867
|
# (tool calls, function results, etc.)
|
|
806
868
|
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
contents.append(Content.from_text(text=""))
|
|
869
|
+
if not messages:
|
|
870
|
+
raise InputConversionError("OpenAI input did not contain any supported message content")
|
|
810
871
|
|
|
811
|
-
|
|
872
|
+
for request_id in approval_request_ids:
|
|
873
|
+
self._pending_approvals.pop(request_id, None)
|
|
812
874
|
|
|
813
|
-
logger.info(
|
|
814
|
-
for idx, content in enumerate(contents):
|
|
815
|
-
content_type = content.__class__.__name__
|
|
816
|
-
if hasattr(content, "media_type"):
|
|
817
|
-
logger.info(f" [{idx}] {content_type} - media_type: {content.media_type}")
|
|
818
|
-
else:
|
|
819
|
-
logger.info(f" [{idx}] {content_type}")
|
|
875
|
+
logger.info("Created %d Message object(s) from OpenAI input", len(messages))
|
|
820
876
|
|
|
821
|
-
return
|
|
877
|
+
return messages[0] if len(messages) == 1 else messages
|
|
822
878
|
|
|
823
879
|
def _extract_user_message_fallback(self, input_data: Any) -> str:
|
|
824
880
|
"""Fallback method to extract user message as string.
|
|
@@ -857,8 +913,11 @@ class AgentFrameworkExecutor:
|
|
|
857
913
|
first_item = input_data_items[0]
|
|
858
914
|
if not isinstance(first_item, dict):
|
|
859
915
|
return False
|
|
860
|
-
|
|
861
|
-
|
|
916
|
+
first_item_dict = cast(dict[str, Any], first_item)
|
|
917
|
+
first_type = first_item_dict.get("type")
|
|
918
|
+
return first_type == "message" or (
|
|
919
|
+
first_type is None and "role" in first_item_dict and "content" in first_item_dict
|
|
920
|
+
)
|
|
862
921
|
|
|
863
922
|
async def _parse_workflow_input(self, workflow: Any, raw_input: Any) -> Any:
|
|
864
923
|
"""Parse input based on workflow's expected input type.
|
|
@@ -893,6 +952,8 @@ class AgentFrameworkExecutor:
|
|
|
893
952
|
# Handle string input
|
|
894
953
|
return self._parse_raw_workflow_input(workflow, str(raw_input))
|
|
895
954
|
|
|
955
|
+
except InputConversionError:
|
|
956
|
+
raise
|
|
896
957
|
except Exception as e:
|
|
897
958
|
logger.warning(f"Error parsing workflow input: {e}")
|
|
898
959
|
return cast(Any, raw_input)
|