Refer to the Installation Guide to complete the setup of the development and runtime environment.
- Go to the Dora Intelligent Agent Template Repository.
- Select the simplest Reasoner Template.
- Copy the template to your development directory.
- Review the template description: README.
Create or edit the reasoner_agent.yml
file:
AGENT:
ROLE: Knowledgeable Assistant
BACKSTORY: <Your background description>
TASK: null # Specific task
RAG:
RAG_ENABLE: false
MODULE_PATH: null
RAG_MODEL_NAME: text-embedding-3-small
COLLECTION_NAME: mofa
IS_UPLOAD_FILE: true
CHROMA_PATH: ./data/output/chroma_store
FILES_PATH:
- ./data/output/arxiv_papers
ENCODING: utf-8
CHUNK_SIZE: 256
RAG_SEARCH_NUM: 2
WEB:
WEB_ENABLE: false
SERPER_API_KEY: <Your Serper API key>
SEARCH_NUM: 20
SEARCH_ENGINE_TIMEOUT: 5
MODEL:
MODEL_API_KEY: <Your model API key>
MODEL_NAME: gpt-4o-mini
MODEL_MAX_TOKENS: 2048
ENV:
PROXY_URL: null
AGENT_TYPE: reasoner
LOG:
LOG_PATH: ./data/output/log/log.md
LOG_TYPE: markdown
LOG_STEP_NAME: reasoner_result
CHECK_LOG_PROMPT: true
- ROLE: Name of the assistant role.
- BACKSTORY: Background description of the assistant.
- TASK: Specific task (default is
null
).
- RAG_ENABLE: Enable (
true
) or disable (false
) RAG. - Other Parameters: Configure knowledge retrieval enhancement features.
- WEB_ENABLE: Enable (
true
) or disable (false
) web search. - SERPER_API_KEY: Serper search API key.
- MODEL_API_KEY: API key for the model service.
- MODEL_NAME: Model name to use (e.g.,
gpt-4o-mini
). - MODEL_MAX_TOKENS: Maximum number of tokens the model can generate.
- PROXY_URL: Proxy server URL (set to
null
if no proxy is needed). - AGENT_TYPE: Agent type, e.g.,
reasoner
.
- LOG_PATH: Path to the log file.
- LOG_TYPE: Log format (e.g.,
markdown
). - LOG_STEP_NAME: Log step name.
- CHECK_LOG_PROMPT: Enable log prompt checking (
true
orfalse
).
Create a reasoner_agent.py
script:
import os
from dora import DoraStatus
import pyarrow as pa
from mofa.kernel.utils.util import load_agent_config, create_agent_output
from mofa.run.run_agent import run_dspy_or_crewai_agent
from mofa.utils.files.dir import get_relative_path
from mofa.utils.log.agent import record_agent_result_log
class Operator:
"""
Dora-rs Operator for handling INPUT events, loading configurations, running the agent, logging results, and sending outputs.
"""
def on_event(self, dora_event, send_output) -> DoraStatus:
if dora_event.get("type") == "INPUT":
agent_inputs = ['data', 'task']
event_id = dora_event.get("id")
if event_id in agent_inputs:
task = dora_event["value"][0].as_py()
yaml_file_path = get_relative_path(
current_file=__file__,
sibling_directory_name='configs',
target_file_name='reasoner_agent.yml'
)
inputs = load_agent_config(yaml_file_path)
inputs["task"] = task
agent_result = run_dspy_or_crewai_agent(agent_config=inputs)
log_step_name = inputs.get('log_step_name', "Step_one")
record_agent_result_log(
agent_config=inputs,
agent_result={f"1, {log_step_name}": {task: agent_result}}
)
output_data = create_agent_output(
agent_name='keyword_results',
agent_result=agent_result,
dataflow_status=os.getenv('IS_DATAFLOW_END', True)
)
send_output(
"reasoner_result",
pa.array([output_data]),
dora_event.get('metadata', {})
)
print('reasoner_results:', agent_result)
return DoraStatus.CONTINUE
Create or edit the reasoner_dataflow.yml
file:
nodes:
- id: terminal-input
build: pip install -e ../../../node-hub/terminal-input
path: dynamic
outputs:
- data
inputs:
reasoner_results: reasoner-agent/reasoner_results
- id: reasoner-agent
operator:
python: scripts/reasoner_agent.py
inputs:
task: terminal-input/data
outputs:
- reasoner_results
- terminal-input:
- Function: Handles initial input.
- Action: Installs the
terminal-input
module. - Output: Generates
data
, passing it toreasoner-agent
. - Input: Receives
reasoner_results
.
- reasoner-agent:
- Function: Processes tasks and generates results.
- Action: Runs the
reasoner_agent.py
script. - Input: Receives
data
fromterminal-input
astask
. - Output: Generates
reasoner_results
, sending them back toterminal-input
.
Run the following commands in the terminal:
dora up
dora build reasoner_dataflow.yml
dora start reasoner_dataflow.yml
Instructions:
dora up
: Initializes the Dora environment.dora build reasoner_dataflow.yml
: Builds the dataflow configuration.dora start reasoner_dataflow.yml
: Starts the dataflow.
-
Open a new terminal window.
-
Run
terminal-input
:terminal-input
-
Enter a task:
Input an
indeed
task in theterminal-input
terminal to start processing.
- Avoid Circular Dependencies: Ensure
terminal-input
receivingreasoner_results
does not trigger new inputs, avoiding infinite loops. - Path Accuracy: Confirm all
pip install
commands and script paths are correct, and modules/scripts are accessible. - Dependency Installation: Ensure the
terminal-input
module and its dependencies are correctly installed. - API Key Security: Keep the API keys in the configuration file secure to prevent leaks.
Following these steps, you have successfully developed and run a simple Hello World intelligent agent based on Dora. The process covers environment setup, template retrieval, configuration file setup, Operator configuration, Dataflow configuration, and running the process. You can further expand and optimize the intelligent agent's functionality as needed.