Code Task Agent
The Code Task Agent is an intelligent assistant designed to help you solve complex data management tasks by writing and executing code for you. Instead of manually writing scripts, you simply describe what you want to achieve, and the agent generates the necessary code, runs it in a secure environment, and provides you with the results.
It acts as a smart developer within your Nappai dashboard, capable of handling tasks that involve data processing, file manipulation, or creating visualizations. It ensures safety by running code in a sandbox (a isolated digital container) so that errors or bugs do not affect your main system.
How it Works
This component operates as an autonomous AI agent. Here is the simple breakdown of its process:
- You Describe the Task: You provide clear instructions describing what you want to achieve (e.g., “Read this CSV file and calculate the average sales per region”).
- AI Generates Code: The agent analyzes your request and generates a Python or Node.js script designed to accomplish that task.
- Safe Execution: The code is executed inside a secure, isolated container (Docker Sandbox). This ensures that any errors or unintended side effects remain contained within this specific task.
- Iterative Problem Solving: If the first attempt fails or produces errors, the agent automatically reviews the error messages, fixes the code, and tries again. It repeats this process until the task is successful or reaches a safe limit of attempts.
- Final Delivery: Once successful, the agent provides you with the final working code, the output of the execution (such as a result or file), and a history of the steps it took.
Because it uses a persistent environment, the agent remembers files and context from previous steps within the same session, making it effective for multi-step workflows.
Connection & Credentials
This component does not require external API credentials to function. It operates locally within your Nappai automation environment. You do not need to configure any API keys or tokens before using it.
Inputs
The following fields are available to configure this component. Each field may be visible in different operations:
-
Instructions: A text field where you describe the specific task or problem you want the agent to solve. Clear and detailed instructions lead to better code generation.
- Visible in: All Operations
-
Initial Code: (Optional) A text field where you can paste existing code to start with, rather than starting from scratch.
- Visible in: All Operations
-
Max Iterations: An integer field that sets the maximum number of attempts the agent will make to solve the problem. This prevents the agent from running indefinitely if it encounters a difficult error.
- Visible in: All Operations
-
Sandbox Configuration: A settings field that allows you to adjust advanced options for the secure environment, such as memory limits or time limits.
- Visible in: All Operations
Outputs
The component produces several outputs that help you understand the result and debug the process if needed.
- Agent: The core agent object, used for further internal processing within the Nappai workflow.
- Response: A message object containing the final communication or summary of the task execution.
Output Data Example (JSON)
json { “status”: “success”, “final_code”: “import pandas as pd\n\ndf = pd.read_csv(‘data.csv’)\nresult = df.groupby(‘region’)[‘sales’].mean()\nprint(result)”, “execution_output”: “region\nNorth 150.5\nSouth 200.3\nName: sales, dtype: float64”, “iteration_history”: [ { “iteration”: 1, “code”: “import pandas as pd\ndf = pd.read_csv(‘data.csv’)”, “error”: null, “success”: true } ] }
Connectivity
This component is typically placed in the middle of a data processing workflow.
- Incoming Connections: It usually receives data from a File Loader or Data Reader component that provides the raw data or files it needs to analyze. You can map your input data to the Instructions or use the Initial Code field to reference these inputs.
- Outgoing Connections: Its outputs (especially execution_output or files created during the sandbox process) can be connected to a Data Writer or Visualization component. The Final Code output can be mapped to a code editor or log viewer for auditing.
Usage Example
Scenario: You need to calculate the average revenue per customer from a large sales CSV file and save the result as a new report.
- Connect a
CSV Readercomponent to this workflow. - Add the Code Task Agent component.
- Set Instructions to: “Read the provided sales data. Calculate the average revenue per customer. Print the top 5 customers by revenue and save the full list as a summary report.”
- Run the workflow.
- Review the Execution Output in the next node to see the calculated averages or the generated file path.
Tips and Best Practices
- Be Specific: The agent works best when instructions are clear. Instead of “fix the data,” say “remove rows where the ‘date’ column is empty.”
- Use Iterations Wisely: If a task is complex, increase the Max Iterations slightly to give the agent more room to correct its own code.
- Check the History: If the agent fails, look at the Iteration History output. It shows the code it tried and why it failed, which helps you understand the problem.
- Start Simple: For complex tasks, break them down into smaller steps. Let the agent handle one small calculation at a time rather than asking it to do everything in one go.
Security Considerations
- Isolated Environment: All code is executed in a secure Docker sandbox. This ensures that your main system files and data remain safe, even if the generated code contains errors or malicious logic.
- Resource Limits: The agent respects memory and time limits defined in the sandbox configuration to prevent any single task from consuming too many system resources.