diff --git a/docs/concepts/clients/devices/app.md b/docs/concepts/clients/devices/app.md new file mode 100644 index 0000000..cffccd2 --- /dev/null +++ b/docs/concepts/clients/devices/app.md @@ -0,0 +1,18 @@ +# AppClient + +## Introduction +`AppClient` is a client tool designed for user interaction within applications. + +## Initialization Parameters +- `interactor`: Optional parameter, workflow used for interaction +- `processor`: Optional parameter, workflow used for image processing +- `config_path`: Optional parameter, path to the worker configuration file +- `workers`: Optional parameter, list of Worker instances + +Note: +1. Either `interactor` or `processor` must be provided +2. At least one of `config_path` or `workers` must be provided, or both can be used + +## Input and Output +- Input: Uses `AppInput` +- Output: Uses `AppCallback` \ No newline at end of file diff --git a/docs/concepts/clients/devices/cli.md b/docs/concepts/clients/devices/cli.md new file mode 100644 index 0000000..9c54908 --- /dev/null +++ b/docs/concepts/clients/devices/cli.md @@ -0,0 +1,22 @@ +# DefaultClient + +## Introduction +`DefaultClient` is the default client used for interacting with users via the command line. + +## Initialization Parameters +- `interactor`: Optional parameter, workflow used for interaction +- `processor`: Optional parameter, workflow used for image processing +- `config_path`: Optional parameter, path to the worker configuration file +- `workers`: Optional parameter, list of Worker instances +- `input_prompt`: Optional parameter, prompt message for user input (defaults to None) + +Note: +1. Either `interactor` or `processor` must be provided +2. At least one of `config_path` or `workers` must be provided, or both can be used +3. If you need a prompt message after startup, you can either: + - Pass it through the `input_prompt` parameter + - Set it in the `self.input.read_input()` method of your first worker node + +## Input and Output +- Input: Uses `AppInput` +- Output: Uses `DefaultCallback` \ No newline at end of file diff --git a/docs/concepts/clients/devices/programmatic.md b/docs/concepts/clients/devices/programmatic.md new file mode 100644 index 0000000..29dab7f --- /dev/null +++ b/docs/concepts/clients/devices/programmatic.md @@ -0,0 +1,75 @@ +# ProgrammaticClient + +## Introduction +`ProgrammaticClient` is a client tool designed for executing batch tasks. + +## Initialization Parameters +- `processor`: Required parameter, the processor for handling tasks +- `config_path`: Optional parameter, path to the worker configuration file +- `workers`: Optional parameter, list of Worker instances + +Note: Either `config_path` or `workers` must be provided. + +## Execution Methods +ProgrammaticClient provides two methods for executing batch tasks: + +### 1. start_batch_processor +Parallel processing of multiple tasks: +```python +# Usage example +workflow_input_list = [] +for i in range(3): + workflow_input_list.append({ + "id": str(i), + "file_path": f"/path/to/test{i}.png" + }) +programmatic_client.start_batch_processor(workflow_input_list=workflow_input_list) +programmatic_client.stop_processor() +``` + +Features: +- Supports multi-process parallel execution +- Default of 5 processes per worker +- Process count can be adjusted via the `concurrency` parameter in the worker configuration file + +### 2. start_processor_with_input +Serial processing of individual tasks: +```python +# Usage example +for i in range(3): + programmatic_client.start_processor_with_input( + workflow_input={"id": str(i), "file_path": f"/path/to/test{i}.png"} + ) +programmatic_client.stop_processor() +``` + +Features: +- Executes one task at a time +- Waits for the current task to complete before executing the next one + +## Parameter Passing +To pass parameters during execution, you need to: +1. Define the corresponding parameters in the worker's `_run` method +2. Specify parameter sources when defining the task + +Example code: +```python +@registry.register_worker() +class SimpleTest(BaseWorker): + def _run(self, id: str, file_path: str): + print("id:", id) + print("file_path:", file_path) + # do something + +# Define task +task1 = simple_task( + task_def_name="SimpleTest", + task_reference_name="simple_test", + inputs={ + "id": workflow.input("id"), + "file_path": workflow.input("file_path") + } +) + +workflow >> task1 +``` \ No newline at end of file diff --git a/docs/concepts/clients/devices/webpage.md b/docs/concepts/clients/devices/webpage.md new file mode 100644 index 0000000..773b44f --- /dev/null +++ b/docs/concepts/clients/devices/webpage.md @@ -0,0 +1,24 @@ +# WebpageClient + +## Introduction +`WebpageClient` is a web-based chat interface implemented with Gradio, designed for interactive communication. + +## Initialization Parameters +- `interactor`: Optional parameter, workflow used for interaction +- `processor`: Optional parameter, workflow used for image processing +- `config_path`: Optional parameter, path to the worker configuration file +- `workers`: Optional parameter, list of Worker instances + +Note: +1. Either `interactor` or `processor` must be provided +2. At least one of `config_path` or `workers` must be provided, or both can be used +3. When using `interactor`: + - Default port: **7860** + - Access URL: `http://127.0.0.1:7860` +4. When using `processor`: + - Default port: **7861** + - Access URL: `http://127.0.0.1:7861` + +## Input and Output +- Input: Uses `AppInput` +- Output: Uses `AppCallback` \ No newline at end of file diff --git a/docs/concepts/clients/client.md b/docs/concepts/clients/input_and_callback.md similarity index 54% rename from docs/concepts/clients/client.md rename to docs/concepts/clients/input_and_callback.md index 5607773..574a975 100644 --- a/docs/concepts/clients/client.md +++ b/docs/concepts/clients/input_and_callback.md @@ -1,27 +1,4 @@ -# Client - -Currently, there are three clients: `DefaultClient`, `AppClient`, and `WebpageClient`. - -`DefaultClient` is the default client used for interacting with users via the command line. -- The parameters of `DefaultClient` include `interactor`, `processor`, `config_path`, `workers`, and `input_prompt`. -- Among them, either `interactor` or `processor` must be chosen to be passed in. `interactor` is the workflow used for interaction, and `processor` is the workflow used for image processing. -- At least one of `config_path` and `workers` must be passed in, or both can be passed. `config_path` is the path to the worker configuration file, and `workers` is a list of `Worker` instances. -- `input_prompt` is the prompt message for user input, which defaults to None. If you need to provide a prompt message after startup, you need to pass it in. Alternatively, you can set `input_prompt` in the `self.input.read_input()` method of your first worker node. - -`AppClient` is used for interacting with users within an app. -- The parameters of `AppClient` include `interactor`, `processor`, `config_path`, and `workers`. -- Among them, either `interactor` or `processor` must be chosen to be passed in. `interactor` is the workflow used for interaction, and `processor` is the workflow used for image processing. -- At least one of `config_path` and `workers` must be passed in, or both can be passed. `config_path` is the path to the worker configuration file, and `workers` is a list of `Worker` instances. - -`WebpageClient` is a web page chat window implemented with gradio, which can be used for interaction. -- The parameters of `WebpageClient` include `interactor`, `processor`, `config_path`, and `workers`. -- Among them, either `interactor` or `processor` must be chosen to be passed in. -- `interactor` is the workflow used for interaction, with a default port of **7860** after startup, and the access address is `http://127.0.0.1:7860`. -- `processor` is the workflow used for image processing, with a default port of **7861** after startup, and the access address is `http://127.0.0.1:7861`. -- At least one of `config_path` and `workers` must be passed in, or both can be passed. `config_path` is the path to the worker configuration file, and `workers` is a list of `Worker` instances. - - -The input for `DefaultClient` uses `AppInput`, and the output uses `DefaultCallback`. The input for `AppClient` uses `AppInput`, and the output uses `AppCallback`. The input for `WebpageClient` uses `AppInput`, and the output uses `AppCallback`. +# Input and Callback When writing an agent worker, you don't need to worry about which one to use. Simply call `self.input.read_input()` and `self.callback.send_xxx()`. Depending on whether `DefaultClient` or `AppClient` or `WebpageClient` is instantiated, different input and output logic will be followed. diff --git a/omagent-core/src/omagent_core/clients/devices/programmatic/client.py b/omagent-core/src/omagent_core/clients/devices/programmatic/client.py index 0adcd5c..b82430b 100644 --- a/omagent-core/src/omagent_core/clients/devices/programmatic/client.py +++ b/omagent-core/src/omagent_core/clients/devices/programmatic/client.py @@ -70,7 +70,6 @@ def _process_workflow(self, workflow:ConductorWorkflow, workflow_input:dict): workflow_instance_id = workflow.start_workflow_with_input(workflow_input=workflow_input) while True: status = workflow.get_workflow(workflow_id=workflow_instance_id).status - print("status:", status) if status in terminal_status: break sleep(1)