Agent Spec Adapters#
Using adapters is the recommended way of integrating an agentic framework runtime. Ideally, an adapter should programmatically translate the representation of the Agent Spec components into the equivalent solution, as per each framework’s definition, and return an object that developers can run.
This page presents all APIs and classes related to Agent Spec Adapters.
LangGraph#
- class pyagentspec.adapters.langgraph.AgentSpecExporter#
Bases:
objectHelper class to convert LangGraph objects into Agent Spec configuration.
- to_component(langgraph_component)#
Transform the given LangGraph component into the respective PyAgentSpec Component.
- Parameters:
langgraph_component (StateGraph[Any, Any, Any, StateT] | CompiledStateGraph[Any, Any, Any, StateT]) – LangGraph Component to serialize to a corresponding PyAgentSpec Component.
- Return type:
- to_json(langgraph_component)#
Transform the given LangGraph component into the respective AgentSpec JSON representation
- Parameters:
langgraph_component (StateGraph[Any, Any, Any, StateT] | CompiledStateGraph[Any, Any, Any, StateT]) – LangGraph Component to serialize to an AgentSpec configuration
- Return type:
str
- to_yaml(langgraph_component)#
Transform the given LangGraph component into the respective AgentSpec YAML representation
- Parameters:
langgraph_component (StateGraph[Any, Any, Any, StateT] | CompiledStateGraph[Any, Any, Any, StateT]) – LangGraph Component to serialize to an AgentSpec configuration
- Return type:
str
- class pyagentspec.adapters.langgraph.AgentSpecLoader(tool_registry=None, plugins=None, checkpointer=None, config=None)#
Bases:
objectHelper class to convert Agent Spec configuration into LangGraph objects.
- Parameters:
tool_registry (Dict[str, Any] | None) – Optional dictionary to enable converting/loading assistant configurations involving the use of tools. Keys must be the tool names as specified in the serialized configuration, and values are either LangGraph/LCEL tools (e.g.,
StructuredTool) or plain callables that will be wrapped.plugins (List[ComponentDeserializationPlugin] | None) – Optional list of Agent Spec deserialization plugins. If omitted, the builtin plugins compatible with the latest supported Agent Spec version are used.
checkpointer (None | bool | BaseCheckpointSaver) – Optional LangGraph checkpointer. If provided, it is wired into created graphs and enables features that require a checkpointer (e.g., client tools).
config (RunnableConfig | None) – Optional
RunnableConfigto pass to created runnables/graphs.
- load_component(agentspec_component)#
Transform the given PyAgentSpec Component into the respective LangGraph component
- Parameters:
agentspec_component (Component) – PyAgentSpec Component to be converted to a LangGraph runtime component (e.g., compiled graph, model, tool).
- Return type:
Any
- load_json(serialized_assistant: str) CompiledStateGraph[Any, Any, Any]#
- load_json(serialized_assistant: str, components_registry: LangGraphComponentsRegistryT | None) CompiledStateGraph[Any, Any, Any]
- load_json(serialized_assistant: str, *, import_only_referenced_components: bool) CompiledStateGraph[Any, Any, Any] | Dict[str, LangGraphRuntimeComponent]
- load_json(serialized_assistant: str, components_registry: LangGraphComponentsRegistryT | None, import_only_referenced_components: bool) CompiledStateGraph[Any, Any, Any] | Dict[str, LangGraphRuntimeComponent]
Transform the given Agent Spec JSON into LangGraph components, with support for disaggregated configurations.
- Parameters:
serialized_assistant – Serialized Agent Spec configuration.
components_registry – Optional registry mapping ids to LangGraph components/values. The loader will convert these back to Agent Spec components/values internally to resolve references during deserialization.
import_only_referenced_components – When
True, loads only the referenced/disaggregated components and returns a dictionary mapping component id to LangGraph components/values. These can be used as thecomponents_registrywhen loading the main configuration. WhenFalse, loads the main component and returns the compiled LangGraph graph.
- Returns:
If
import_only_referenced_componentsisFalseCompiledStateGraph – The compiled LangGraph component.
If
import_only_referenced_componentsisTrueDict[str, LangGraphRuntimeComponent] – A dictionary containing the converted referenced components.
Examples
Basic two-phase loading with disaggregation:
>>> from pyagentspec.agent import Agent >>> from pyagentspec.llms import OllamaConfig >>> from pyagentspec.serialization import AgentSpecSerializer >>> agent = Agent(id="agent_id", name="A", system_prompt="You are helpful.", llm_config=OllamaConfig(id="llm_id", name="m", model_id="llama3.1", url="http://localhost:11434")) >>> main_json, disag_json = AgentSpecSerializer().to_json( ... agent, disaggregated_components=[(agent.llm_config, "llm_id")], export_disaggregated_components=True ... ) >>> from pyagentspec.adapters.langgraph import AgentSpecLoader >>> loader = AgentSpecLoader() >>> registry = loader.load_json(disag_json, import_only_referenced_components=True) >>> langgraph = loader.load_json(main_json, components_registry=registry)
Alternatively, you can deserialize the disaggregated components with the pyagentspec deserializer and pass them into the load of the main component:
>>> from pyagentspec.serialization import AgentSpecDeserializer >>> referenced_components = AgentSpecDeserializer().from_json(disag_json, import_only_referenced_components=True) >>> langgraph = loader.load_json(main_json, components_registry=referenced_components)
- load_yaml(serialized_assistant: str) CompiledStateGraph[Any, Any, Any]#
- load_yaml(serialized_assistant: str, components_registry: LangGraphComponentsRegistryT | None) CompiledStateGraph[Any, Any, Any]
- load_yaml(serialized_assistant: str, *, import_only_referenced_components: bool) CompiledStateGraph[Any, Any, Any] | Dict[str, LangGraphRuntimeComponent]
- load_yaml(serialized_assistant: str, components_registry: LangGraphComponentsRegistryT | None, import_only_referenced_components: bool) CompiledStateGraph[Any, Any, Any] | Dict[str, LangGraphRuntimeComponent]
Transform the given Agent Spec YAML into LangGraph components, with support for disaggregated configurations.
- Parameters:
serialized_assistant – Serialized Agent Spec configuration.
components_registry – Optional registry mapping ids to LangGraph components/values. The loader will convert these back to Agent Spec components/values internally to resolve references during deserialization.
import_only_referenced_components – When
True, loads only the referenced/disaggregated components and returns a dictionary mapping component id to LangGraph components/values. These can be used as thecomponents_registrywhen loading the main configuration. WhenFalse, loads the main component and returns the compiled LangGraph graph.
- Returns:
If
import_only_referenced_componentsisFalseCompiledStateGraph – The compiled LangGraph component.
If
import_only_referenced_componentsisTrueDict[str, LangGraphRuntimeComponent] – A dictionary containing the converted referenced components.
Examples
Basic two-phase loading with disaggregation:
>>> from pyagentspec.agent import Agent >>> from pyagentspec.llms import OllamaConfig >>> from pyagentspec.serialization import AgentSpecSerializer >>> agent = Agent(id="agent_id", name="A", system_prompt="You are helpful.", llm_config=OllamaConfig(name="m", model_id="llama3.1", url="http://localhost:11434")) >>> main_yaml, disag_yaml = AgentSpecSerializer().to_yaml( ... agent, disaggregated_components=[(agent.llm_config, "llm_id")], export_disaggregated_components=True ... ) >>> from pyagentspec.adapters.langgraph import AgentSpecLoader >>> loader = AgentSpecLoader() >>> registry = loader.load_yaml(disag_yaml, import_only_referenced_components=True) >>> compiled = loader.load_yaml(main_yaml, components_registry=registry)
Alternatively, you can deserialize the disaggregated components with the pyagentspec deserializer and pass them into the load of the main component:
>>> from pyagentspec.serialization import AgentSpecDeserializer >>> referenced_components = AgentSpecDeserializer().from_yaml(disag_yaml, import_only_referenced_components=True) >>> langgraph = loader.load_yaml(main_yaml, components_registry=referenced_components)
CrewAI#
- class pyagentspec.adapters.crewai.AgentSpecExporter#
Bases:
objectHelper class to convert CrewAI objects to Agent Spec configurations.
- to_component(crewai_component)#
Transform the given CrewAI component into the respective PyAgentSpec Component.
- Parameters:
crewai_component (Agent | _FlowGeneric) – CrewAI Component to serialize to a corresponding PyAgentSpec Component.
- Return type:
- to_json(crewai_component)#
Transform the given CrewAI component into the respective Agent Spec JSON representation.
- Parameters:
crewai_component (Agent | _FlowGeneric) – CrewAI Component to serialize to an Agent Spec configuration.
- Return type:
str
- to_yaml(crewai_component)#
Transform the given CrewAI component into the respective Agent Spec YAML representation.
- Parameters:
crewai_component (Agent | _FlowGeneric) – CrewAI Component to serialize to an Agent Spec configuration.
- Return type:
str
- class pyagentspec.adapters.crewai.AgentSpecLoader(tool_registry=None, plugins=None)#
Bases:
objectHelper class to convert Agent Spec configurations to CrewAI objects.
- Parameters:
tool_registry (Dict[str, Tool | Callable[[...], Any]] | None) –
plugins (List[ComponentDeserializationPlugin] | None) –
- load_component(agentspec_component)#
Transform the given PyAgentSpec Component into the respective CrewAI Component
- Parameters:
agentspec_component (Component) – PyAgentSpec Component to be converted to a CrewAI Component.
- Return type:
Agent | _FlowGeneric
- load_json(serialized_assistant)#
Transform the given Agent Spec JSON representation into the respective CrewAI Component
- Parameters:
serialized_assistant (str) – Serialized Agent Spec configuration to be converted to a CrewAI Component.
- Return type:
Agent | _FlowGeneric
- load_yaml(serialized_assistant)#
Transform the given Agent Spec YAML representation into the respective CrewAI Component
- Parameters:
serialized_assistant (str) – Serialized Agent Spec configuration to be converted to a CrewAI Component.
- Return type:
Agent | _FlowGeneric
AutoGen#
- class pyagentspec.adapters.autogen.AgentSpecExporter#
Bases:
objectHelper class to convert AutoGen objects to Agent Spec configurations.
- to_component(autogen_component)#
Transform the given AutoGen component into the respective PyAgentSpec Component.
- Parameters:
autogen_component (Component) – AutoGen Component to transform into a corresponding PyAgentSpec Component.
- Returns:
The PyAgentSpec Component corresponding to the AutoGen component.
- Return type:
- Raises:
TypeError – If the input is not an AutoGen Component.
- to_json(autogen_component)#
Transform the given AutoGen component into the respective Agent Spec JSON representation.
- Parameters:
autogen_component (Component) – AutoGen Component to serialize to an Agent Spec configuration.
- Returns:
The Agent Spec JSON representation of the AutoGen component.
- Return type:
str
- to_yaml(autogen_component)#
Transform the given AutoGen component into the respective Agent Spec YAML representation.
- Parameters:
autogen_component (Component) – AutoGen Component to serialize to an Agent Spec configuration.
- Returns:
The Agent Spec YAML representation of the AutoGen component.
- Return type:
str
- class pyagentspec.adapters.autogen.AgentSpecLoader(tool_registry=None, plugins=None)#
Bases:
objectHelper class to convert Agent Spec configurations to AutoGen objects.
- Parameters:
tool_registry (Dict[str, FunctionTool | Callable[[...], Any]] | None) –
plugins (List[ComponentDeserializationPlugin] | None) –
- load_component(agentspec_component)#
Transform the given PyAgentSpec Component into the respective AutoGen Component
- Parameters:
agentspec_component (Component) – PyAgentSpec Component to be converted to an AutoGen Component.
- Return type:
AssistantAgent
- load_json(serialized_assistant)#
Transform the given Agent Spec JSON representation into the respective AutoGen Component
- Parameters:
serialized_assistant (str) – Serialized Agent Spec configuration to be converted to an AutoGen Component.
- Return type:
AssistantAgent
- load_yaml(serialized_assistant)#
Transform the given Agent Spec YAML representation into the respective AutoGen Component
- Parameters:
serialized_assistant (str) – Serialized Agent Spec configuration to be converted to an AutoGen Component.
- Return type:
AssistantAgent
WayFlow#
- class pyagentspec.adapters.wayflow.AgentSpecExporter(plugins=None)#
Bases:
objectHelper class to convert WayFlow objects to Agent Spec configurations.
- Parameters:
plugins (List[ComponentSerializationPlugin] | None) –
- to_component(runtime_component)#
Transform the given WayFlow component into the respective PyAgentSpec Component.
- Parameters:
runtime_component (Component) – WayFlow Component to serialize to a corresponding PyAgentSpec Component.
- Return type:
- to_json(runtime_component: RuntimeComponent) str#
- to_json(runtime_component: RuntimeComponent, agentspec_version: AgentSpecVersionEnum | None) str
- to_json(runtime_component: RuntimeComponent, *, disaggregated_components: RuntimeDisaggregatedComponentsConfigT, export_disaggregated_components: Literal[True]) Tuple[str, str]
- to_json(runtime_component: RuntimeComponent, *, disaggregated_components: RuntimeDisaggregatedComponentsConfigT | None, export_disaggregated_components: Literal[False]) str
- to_json(runtime_component: RuntimeComponent, *, disaggregated_components: RuntimeDisaggregatedComponentsConfigT | None, export_disaggregated_components: bool) str | Tuple[str, str]
- to_json(runtime_component: RuntimeComponent, agentspec_version: AgentSpecVersionEnum | None, disaggregated_components: RuntimeDisaggregatedComponentsConfigT | None, export_disaggregated_components: bool) str | Tuple[str, str]
Transform the given WayFlow component into the respective Agent Spec JSON representation.
- Parameters:
runtime_component – WayFlow component to serialize to an Agent Spec configuration.
agentspec_version – The Agent Spec version of the component.
disaggregated_components –
Configuration specifying the components/fields to disaggregate upon serialization. Each item can be:
A
Component: to disaggregate the component using its idA tuple
(Component, str): to disaggregate the component using a custom id.
Note
Components in
disaggregated_componentsare disaggregated even ifexport_disaggregated_componentsisFalse.export_disaggregated_components – Whether to export the disaggregated components or not. Defaults to
False.
- Returns:
If
export_disaggregated_componentsisTruestr – The JSON serialization of the root component.
str – The JSON serialization of the disaggregated components.
If
export_disaggregated_componentsisFalsestr – The JSON serialization of the root component.
Examples
Basic serialization is done as follows.
>>> from wayflowcore.agent import Agent >>> from wayflowcore.agentspec import AgentSpecExporter >>> from wayflowcore.models import VllmModel >>> from wayflowcore.tools import tool >>> >>> llm = VllmModel( ... model_id="model-id", ... host_port="VLLM_HOST_PORT", ... ) >>> @tool ... def say_hello_tool() -> str: ... '''This tool returns "hello"''' ... return "hello" ... >>> agent = Agent( ... name="Simple Agent", ... llm=llm, ... tools=[say_hello_tool] ... ) >>> config = AgentSpecExporter().to_json(agent)
To use component disaggregation, specify the component(s) to disaggregate in the
disaggregated_componentsparameter, and ensure thatexport_disaggregated_componentsis set toTrue.>>> main_config, disag_config = AgentSpecExporter().to_json( ... agent, ... disaggregated_components=[llm], ... export_disaggregated_components=True ... )
Finally, you can specify custom ids for the disaggregated components.
>>> main_config, disag_config = AgentSpecExporter().to_json( ... agent, ... disaggregated_components=[(llm, "custom_llm_id")], ... export_disaggregated_components=True ... )
- to_yaml(runtime_component: RuntimeComponent) str#
- to_yaml(runtime_component: RuntimeComponent, agentspec_version: AgentSpecVersionEnum | None) str
- to_yaml(runtime_component: RuntimeComponent, *, disaggregated_components: RuntimeDisaggregatedComponentsConfigT, export_disaggregated_components: Literal[True]) Tuple[str, str]
- to_yaml(runtime_component: RuntimeComponent, *, disaggregated_components: RuntimeDisaggregatedComponentsConfigT | None, export_disaggregated_components: Literal[False]) str
- to_yaml(runtime_component: RuntimeComponent, *, disaggregated_components: RuntimeDisaggregatedComponentsConfigT | None, export_disaggregated_components: bool) str | Tuple[str, str]
- to_yaml(runtime_component: RuntimeComponent, agentspec_version: AgentSpecVersionEnum | None, disaggregated_components: RuntimeDisaggregatedComponentsConfigT | None, export_disaggregated_components: bool) str | Tuple[str, str]
Transform the given WayFlow component into the respective Agent Spec YAML representation.
- Parameters:
runtime_component – WayFlow component to serialize to an Agent Spec configuration.
agentspec_version – The Agent Spec version of the component.
disaggregated_components –
Configuration specifying the components/fields to disaggregate upon serialization. Each item can be:
A
Component: to disaggregate the component using its idA tuple
(Component, str): to disaggregate the component using a custom id.
Note
Components in
disaggregated_componentsare disaggregated even ifexport_disaggregated_componentsisFalse.export_disaggregated_components – Whether to export the disaggregated components or not. Defaults to
False.
- Returns:
If
export_disaggregated_componentsisTruestr – The YAML serialization of the root component.
str – The YAML serialization of the disaggregated components.
If
export_disaggregated_componentsisFalsestr – The YAML serialization of the root component.
Examples
Basic serialization is done as follows.
>>> from wayflowcore.agent import Agent >>> from wayflowcore.agentspec import AgentSpecExporter >>> from wayflowcore.models import VllmModel >>> from wayflowcore.tools import tool >>> >>> llm = VllmModel( ... model_id="model-id", ... host_port="VLLM_HOST_PORT", ... ) >>> @tool ... def say_hello_tool() -> str: ... '''This tool returns "hello"''' ... return "hello" ... >>> agent = Agent( ... name="Simple Agent", ... llm=llm, ... tools=[say_hello_tool] ... ) >>> config = AgentSpecExporter().to_yaml(agent)
To use component disaggregation, specify the component(s) to disaggregate in the
disaggregated_componentsparameter, and ensure thatexport_disaggregated_componentsis set toTrue.>>> main_config, disag_config = AgentSpecExporter().to_yaml( ... agent, ... disaggregated_components=[llm], ... export_disaggregated_components=True ... )
Finally, you can specify custom ids for the disaggregated components.
>>> main_config, disag_config = AgentSpecExporter().to_yaml( ... agent, ... disaggregated_components=[(llm, "custom_llm_id")], ... export_disaggregated_components=True ... )
- class pyagentspec.adapters.wayflow.AgentSpecLoader(tool_registry=None, plugins=None)#
Bases:
objectHelper class to convert Agent Spec configurations to WayFlow objects.
- Parameters:
tool_registry (Dict[str, ServerTool | Callable[[...], Any]] | None) –
plugins (List[ComponentDeserializationPlugin] | None) –
- load_component(agentspec_component)#
Transform the given PyAgentSpec Component into the respective WayFlow Component
- Parameters:
agentspec_component (Component) – PyAgentSpec Component to be converted to a WayFlow Component.
- Return type:
Component
- load_json(serialized_assistant: str) RuntimeComponent#
- load_json(serialized_assistant: str, components_registry: RuntimeComponentsRegistryT | None) RuntimeComponent
- load_json(serialized_assistant: str, *, import_only_referenced_components: Literal[False]) RuntimeComponent
- load_json(serialized_assistant: str, *, import_only_referenced_components: Literal[True]) Dict[str, RuntimeComponent]
- load_json(serialized_assistant: str, *, import_only_referenced_components: bool) RuntimeComponent | Dict[str, RuntimeComponent]
- load_json(serialized_assistant: str, components_registry: RuntimeComponentsRegistryT | None, import_only_referenced_components: Literal[False]) RuntimeComponent
- load_json(serialized_assistant: str, components_registry: RuntimeComponentsRegistryT | None, import_only_referenced_components: Literal[True]) Dict[str, RuntimeComponent]
- load_json(serialized_assistant: str, components_registry: RuntimeComponentsRegistryT | None, import_only_referenced_components: bool) RuntimeComponent | Dict[str, RuntimeComponent]
Transform the given Agent Spec JSON representation into the respective WayFlow Component
- Parameters:
serialized_assistant – Serialized Agent Spec configuration to be converted to a WayFlow Component.
components_registry – A dictionary of loaded WayFlow components to use when deserializing the main component.
import_only_referenced_components – When
True, loads the referenced/disaggregated components into a dictionary to be used as thecomponents_registrywhen deserializing the main component. Otherwise, loads the main component. Defaults toFalse
- Returns:
If
import_only_referenced_componentsisFalseComponent – The deserialized component.
If
import_only_referenced_componentsisFalseDict[str, Component] – A dictionary containing the loaded referenced components.
Examples
Basic deserialization is done as follows. First, serialize a component (here an
Agent).>>> from wayflowcore.agent import Agent >>> from wayflowcore.agentspec import AgentSpecExporter >>> from wayflowcore.models import VllmModel >>> from wayflowcore.tools import tool >>> llm = VllmModel( ... model_id="model-id", ... host_port="VLLM_HOST_PORT", ... ) >>> @tool ... def say_hello_tool() -> str: ... '''This tool returns "hello"''' ... return "hello" ... >>> agent = Agent( ... name="Simple Agent", ... llm=llm, ... tools=[say_hello_tool] ... ) >>> config = AgentSpecExporter().to_json(agent)
Then deserialize using the
AgentSpecLoader.>>> from wayflowcore.agentspec import AgentSpecLoader >>> TOOL_REGISTRY = {"say_hello_tool": say_hello_tool} >>> loader = AgentSpecLoader(tool_registry=TOOL_REGISTRY) >>> deser_agent = loader.load_json(config)
When using disaggregated components, the deserialization must be done in several phases, as follows.
>>> main_config, disag_config = AgentSpecExporter().to_json( ... agent, ... disaggregated_components=[(llm, "custom_llm_id")], ... export_disaggregated_components=True ... ) >>> TOOL_REGISTRY = {"say_hello_tool": say_hello_tool} >>> loader = AgentSpecLoader(tool_registry=TOOL_REGISTRY) >>> disag_components = loader.load_json( ... disag_config, import_only_referenced_components=True ... ) >>> deser_agent = loader.load_json( ... main_config, ... components_registry=disag_components ... )
- load_yaml(serialized_assistant: str) RuntimeComponent#
- load_yaml(serialized_assistant: str, components_registry: RuntimeComponentsRegistryT | None) RuntimeComponent
- load_yaml(serialized_assistant: str, *, import_only_referenced_components: Literal[False]) RuntimeComponent
- load_yaml(serialized_assistant: str, *, import_only_referenced_components: Literal[True]) Dict[str, RuntimeComponent]
- load_yaml(serialized_assistant: str, *, import_only_referenced_components: bool) RuntimeComponent | Dict[str, RuntimeComponent]
- load_yaml(serialized_assistant: str, components_registry: RuntimeComponentsRegistryT | None, import_only_referenced_components: Literal[False]) RuntimeComponent
- load_yaml(serialized_assistant: str, components_registry: RuntimeComponentsRegistryT | None, import_only_referenced_components: Literal[True]) Dict[str, RuntimeComponent]
- load_yaml(serialized_assistant: str, components_registry: RuntimeComponentsRegistryT | None, import_only_referenced_components: bool) RuntimeComponent | Dict[str, RuntimeComponent]
Transform the given Agent Spec YAML representation into the respective WayFlow Component
- Parameters:
serialized_assistant – Serialized Agent Spec configuration to be converted to a WayFlow Component.
components_registry – A dictionary of loaded WayFlow components to use when deserializing the main component.
import_only_referenced_components – When
True, loads the referenced/disaggregated components into a dictionary to be used as thecomponents_registrywhen deserializing the main component. Otherwise, loads the main component. Defaults toFalse
- Returns:
If
import_only_referenced_componentsisFalseComponent – The deserialized component.
If
import_only_referenced_componentsisFalseDict[str, Component] – A dictionary containing the loaded referenced components.
Examples
Basic deserialization is done as follows. First, serialize a component (here an
Agent).>>> from wayflowcore.agent import Agent >>> from wayflowcore.agentspec import AgentSpecExporter >>> from wayflowcore.models import VllmModel >>> from wayflowcore.tools import tool >>> llm = VllmModel( ... model_id="model-id", ... host_port="VLLM_HOST_PORT", ... ) >>> @tool ... def say_hello_tool() -> str: ... '''This tool returns "hello"''' ... return "hello" ... >>> agent = Agent( ... name="Simple Agent", ... llm=llm, ... tools=[say_hello_tool] ... ) >>> config = AgentSpecExporter().to_yaml(agent)
Then deserialize using the
AgentSpecLoader.>>> from wayflowcore.agentspec import AgentSpecLoader >>> TOOL_REGISTRY = {"say_hello_tool": say_hello_tool} >>> loader = AgentSpecLoader(tool_registry=TOOL_REGISTRY) >>> deser_agent = loader.load_yaml(config)
When using disaggregated components, the deserialization must be done in several phases, as follows.
>>> main_config, disag_config = AgentSpecExporter().to_yaml( ... agent, ... disaggregated_components=[(llm, "custom_llm_id")], ... export_disaggregated_components=True ... ) >>> TOOL_REGISTRY = {"say_hello_tool": say_hello_tool} >>> loader = AgentSpecLoader(tool_registry=TOOL_REGISTRY) >>> disag_components = loader.load_yaml( ... disag_config, import_only_referenced_components=True ... ) >>> deser_agent = loader.load_yaml( ... main_config, ... components_registry=disag_components ... )
Microsoft Agent Framework#
- class pyagentspec.adapters.agent_framework.AgentSpecExporter(plugins=None)#
Bases:
objectHelper class to convert Microsoft Agent Framework objects to Agent Spec configurations.
- Parameters:
plugins (list[pyagentspec.serialization.serializationplugin.ComponentSerializationPlugin] | None) –
- to_component(agent_framework_component)#
Transform the given Microsoft Agent Framework component into the respective PyAgentSpec Component.
- Parameters:
agent_framework_component (ChatAgent) – Microsoft Agent Framework Component to serialize to a corresponding PyAgentSpec Component.
- Return type:
- to_json(agent_framework_component)#
Transform the given Microsoft Agent Framework component into the respective Agent Spec JSON representation.
- Parameters:
agent_framework_component (ChatAgent) – Microsoft Agent Framework Component to serialize to an Agent Spec configuration.
- Return type:
str
- to_yaml(agent_framework_component)#
Transform the given Microsoft Agent Framework component into the respective Agent Spec YAML representation.
- Parameters:
agent_framework_component (ChatAgent) – Microsoft Agent Framework Component to serialize to an Agent Spec configuration.
- Return type:
str
- class pyagentspec.adapters.agent_framework.AgentSpecLoader(tool_registry=None, plugins=None)#
Bases:
objectHelper class to convert Agent Spec configurations to Microsoft Agent Framework objects.
- Parameters:
tool_registry (dict[str, Union[agent_framework._tools.ToolProtocol, agent_framework._tools.FunctionTool[Any, Any], Callable[..., Any], MutableMapping[str, Any], Sequence[Union[agent_framework._tools.ToolProtocol, Callable[..., Any], MutableMapping[str, Any]]]]] | None) –
plugins (list[pyagentspec.serialization.deserializationplugin.ComponentDeserializationPlugin] | None) –
- load_component(agentspec_component)#
Transform the given PyAgentSpec Component into the respective Microsoft Agent Framework Component
- Parameters:
agentspec_component (Component) – PyAgentSpec Component to be converted to a Microsoft Agent Framework Component.
- Return type:
ChatAgent
- load_json(serialized_assistant)#
Transform the given Agent Spec JSON representation into the respective Microsoft Agent Framework Component
- Parameters:
serialized_assistant (str) – Serialized Agent Spec configuration to be converted to a Microsoft Agent Framework Component.
- Return type:
ChatAgent
- load_yaml(serialized_assistant)#
Transform the given Agent Spec YAML representation into the respective Microsoft Agent Framework Component
- Parameters:
serialized_assistant (str) – Serialized Agent Spec configuration to be converted to a Microsoft Agent Framework Component.
- Return type:
ChatAgent