Skip to content

Python: [Bug]: Declarative YAML path loaders are locale-dependent and async loader blocks the event loop #8254

Description

@fzfzzfzzzfzzzz

Description

The Python declarative path loaders read YAML using the process locale instead of UTF-8:

  • AgentFactory.create_agent_from_yaml_path() uses open(yaml_path).
  • AgentFactory.create_agent_from_yaml_path_async() uses Path.read_text().
  • WorkflowFactory.create_workflow_from_yaml_path() uses open(yaml_path).

On Windows with a non-UTF-8 locale, a UTF-8 YAML file containing characters outside that locale can fail before YAML parsing. The async agent loader also performs Path.exists() and Path.read_text() directly on the event-loop thread even though it is presented as an async counterpart.

Expected behavior:

  1. Path-based declarative YAML loading should consistently read UTF-8 files across platforms.
  2. The async path loader should offload filesystem access rather than blocking the event loop.

I intend to submit a focused fix with regression tests covering Unicode YAML and event-loop responsiveness.

Code Sample

from pathlib import Path

from agent_framework_declarative import WorkflowFactory

path = Path("unicode-workflow.yaml")
path.write_text(
    """kind: Workflow
trigger:
  kind: OnConversationStart
  id: start
  actions:
    - kind: SendActivity
      id: reply
      activity: "政务助手 🏛️"
""",
    encoding="utf-8",
)

WorkflowFactory().create_workflow_from_yaml_path(path)

Error Messages / Stack Traces

On Windows with locale.getencoding() == "cp936" and UTF-8 mode disabled:

UnicodeDecodeError: 'gbk' codec can't decode byte ...

Package Versions

agent-framework-declarative: source checkout of main at d7823b2

Python Version

Python 3.11.9

Additional Context

The synchronous and asynchronous agent loaders and the workflow loader should use the same explicit encoding. For the async method, reading through asyncio.to_thread() would also avoid blocking on local, network, or otherwise slow filesystems.

AI assistance was used to audit the code paths and prepare the reproduction; the behavior was verified against the referenced source checkout.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

declarativeUsage: [Issues, PRs], Target: declarative agents and workflowspythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions