-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated external workflow loading into langchain agent
- Loading branch information
1 parent
cd4778b
commit 56c74aa
Showing
8 changed files
with
189 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/python/PythonSDK/foundationallm/langchain/common/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .foundationallm_tool_base import FoundationaLLMToolBase | ||
from .foundationallm_workflow_base import FoundationaLLMWorkflowBase |
68 changes: 68 additions & 0 deletions
68
src/python/PythonSDK/foundationallm/langchain/common/foundationallm_workflow_base.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
""" | ||
Class: FoundationaLLMWorkflowBase | ||
Description: FoundationaLLM base class for tools that uses the agent workflow model for its configuration. | ||
""" | ||
from abc import ABC, abstractmethod | ||
from azure.identity import DefaultAzureCredential | ||
from langchain_core.messages import BaseMessage | ||
from pydantic import BaseModel | ||
from typing import List | ||
from foundationallm.config import Configuration, UserIdentity | ||
from foundationallm.models.agents import AgentTool, ExternalAgentWorkflow | ||
from foundationallm.models.orchestration import CompletionResponse | ||
from foundationallm.telemetry import Telemetry | ||
|
||
class FoundationaLLMWorkflowBase(BaseModel, ABC): | ||
""" | ||
FoundationaLLM base class for workflows that uses the agent workflow model for its configuration. | ||
""" | ||
def __init__(self, | ||
workflow_config: ExternalAgentWorkflow, | ||
objects: dict, | ||
tools: List[AgentTool], | ||
user_identity: UserIdentity, | ||
config: Configuration): | ||
""" | ||
Initializes the FoundationaLLMWorkflowBase class with the workflow configuration. | ||
Parameters | ||
---------- | ||
workflow_config : ExternalAgentWorkflow | ||
The workflow assigned to the agent. | ||
objects : dict | ||
The exploded objects assigned from the agent. | ||
tools : List[AgentTool] | ||
The tools assigned to the agent. | ||
user_identity : UserIdentity | ||
The user identity of the user initiating the request. | ||
config : Configuration | ||
The application configuration for FoundationaLLM. | ||
""" | ||
self.workflow_config = workflow_config | ||
self.objects = objects | ||
self.tools = tools if tools is not None else [] | ||
self.user_identity = user_identity | ||
self.config = config | ||
self.logger = Telemetry.get_logger(self.workflow_config.name) | ||
self.tracer = Telemetry.get_tracer(self.workflow_config.name) | ||
self.default_credential = DefaultAzureCredential(exclude_environment_credential=True) | ||
|
||
@abstractmethod | ||
async def invoke_async(self, | ||
user_prompt:str, | ||
message_history: List[BaseMessage])-> CompletionResponse: | ||
""" | ||
Invokes the workflow asynchronously. | ||
Parameters | ||
---------- | ||
user_prompt : str | ||
The user prompt message. | ||
message_history : List[BaseMessage] | ||
The message history. | ||
""" | ||
pass | ||
|
||
class Config: | ||
""" Pydantic configuration for FoundationaLLMWorkflowBase. """ | ||
extra = "allow" |
2 changes: 1 addition & 1 deletion
2
src/python/PythonSDK/foundationallm/langchain/workflows/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .workflow_factory import WorkflowFactory | ||
from .external_workflow_factory import ExternalWorkflowFactory |
56 changes: 56 additions & 0 deletions
56
src/python/PythonSDK/foundationallm/langchain/workflows/external_workflow_factory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
Class: WorkflowFactory | ||
Description: Factory class for creating an external workflow instance based on the Agent workflow configuration. | ||
""" | ||
from typing import List | ||
from foundationallm.config import Configuration, UserIdentity | ||
from foundationallm.langchain.common import FoundationaLLMWorkflowBase | ||
from foundationallm.langchain.exceptions import LangChainException | ||
from foundationallm.models.agents import AgentTool, ExternalAgentWorkflow | ||
from foundationallm.plugins import PluginManager | ||
|
||
class ExternalWorkflowFactory: | ||
""" | ||
Factory class for creating an external agent workflow instance based on the Agent workflow configuration. | ||
""" | ||
def __init__(self, plugin_manager: PluginManager): | ||
""" | ||
Initializes the workflow factory. | ||
Parameters | ||
---------- | ||
plugin_manager : PluginManager | ||
The plugin manager object used to load external workflows. | ||
""" | ||
self.plugin_manager = plugin_manager | ||
|
||
def get_workflow( | ||
self, | ||
workflow_config: ExternalAgentWorkflow, | ||
objects: dict, | ||
tools: List[AgentTool], | ||
user_identity: UserIdentity, | ||
config: Configuration | ||
) -> FoundationaLLMWorkflowBase: | ||
""" | ||
Creates an instance of an external agent workflow based on the agent workflow configuration. | ||
Parameters | ||
---------- | ||
workflow_config : ExternalAgentWorkflow | ||
The workflow assigned to the agent. | ||
objects : dict | ||
The exploded objects assigned from the agent. | ||
tools : List[AgentTool] | ||
The tools assigned to the agent. | ||
user_identity : UserIdentity | ||
The user identity of the user initiating the request. | ||
config : Configuration | ||
The application configuration for FoundationaLLM. | ||
""" | ||
workflow_plugin_manager = None | ||
if workflow_config.package_name in self.plugin_manager.external_modules: | ||
workflow_plugin_manager = self.plugin_manager.external_modules[workflow_config.package_name].plugin_manager | ||
return workflow_plugin_manager.create_workflow(workflow_config, objects, tools, user_identity, config) | ||
else: | ||
raise LangChainException(f"Package {workflow_config.package_name} not found in the list of external modules loaded by the package manager.") |
49 changes: 0 additions & 49 deletions
49
src/python/PythonSDK/foundationallm/langchain/workflows/workflow_factory.py
This file was deleted.
Oops, something went wrong.
25 changes: 23 additions & 2 deletions
25
src/python/PythonSDK/foundationallm/plugins/workflows/workflow_plugin_manager_base.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters