> ## Documentation Index
> Fetch the complete documentation index at: https://docs.triform.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Editing with Triton

> Modify and refine your Projects using AI assistance

## Overview

After building components, you'll often need to refine them. Triton can help you modify code, update prompts, restructure Flows, and optimize performance through natural conversation.

## Editing Actions

### Code modifications

**Simple changes:**

*"Add logging to this Action"*\
*"Add a timeout parameter"*\
*"Remove the deprecated function"*\
*"Rename the parameter from 'data' to 'input\_data'"*

**Refactoring:**

*"Extract the validation logic into a separate function"*\
*"Convert this to async/await"*\
*"Replace the for loop with a list comprehension"*\
*"Add type hints to all functions"*

**Error handling:**

*"Add try-catch for JSON parsing errors"*\
*"Handle the case where the API returns 404"*\
*"Add validation for negative numbers"*\
*"Return a default value if the request fails"*

### Example: Adding retry logic

**You:** *"Add retry logic to this API call"*

**Triton modifies:**

Before:

```python theme={null}
def fetch_data(url: str) -> dict:
    response = requests.get(url)
    return response.json()
```

After:

```python theme={null}
from tenacity import retry, stop_after_attempt, wait_exponential
import requests

@retry(
    stop=stop_after_attempt(3),
    wait=wait_exponential(multiplier=1, min=2, max=10)
)
def fetch_data(url: str) -> dict:
    """Fetches data with automatic retry on failure."""
    response = requests.get(url, timeout=10)
    response.raise_for_status()
    return response.json()
```

And updates `requirements.txt`:

```
requests==2.31.0
tenacity==8.2.3
```

### Performance optimizations

*"Cache the results of this expensive function"*\
*"Batch the API calls instead of calling one at a time"*\
*"Use a connection pool"*\
*"Add async for I/O operations"*

## Editing Agents

### Prompt refinement

**Tone adjustments:**

*"Make this Agent more formal"*\
*"Make responses more concise"*\
*"Add a friendly, conversational tone"*\
*"Make it sound like a technical expert"*

**Behavior changes:**

*"Always ask for confirmation before taking actions"*\
*"Include sources for all facts mentioned"*\
*"Format responses as markdown"*\
*"Add step-by-step reasoning"*

**Example: Refining a support Agent**

**You:** *"Make this support Agent more empathetic and proactive"*

**Triton updates system prompt:**

Before:

```
You are a customer support assistant. Answer questions about our products.
```

After:

```
You are an empathetic customer support specialist dedicated to helping customers succeed.

Approach:
1. Acknowledge the customer's situation and any frustration
2. Provide clear, actionable solutions
3. Proactively suggest related help or preventive measures
4. Always confirm if the issue is resolved

Tone: Warm, patient, and professional. Show genuine care for the customer's experience.

Use available tools to check account status, create tickets, or look up documentation.
Always explain what you're doing and why.
```

### Tool management

**Adding tools:**

*"Add the search\_documentation Action as a tool"*\
*"Give this Agent access to the billing\_update Flow"*

**Removing tools:**

*"Remove the delete\_account tool—it's too risky"*\
*"This Agent shouldn't have access to user\_data anymore"*

**Tool usage guidance:**

*"Update the prompt to encourage using the search tool first"*\
*"Add examples of when to use each tool"*\
*"Clarify that create\_ticket should be used only when unable to resolve"*

### Model and parameter adjustments

*"Switch this Agent to Claude instead of GPT-4"*\
*"Lower the temperature to 0.2 for more consistent output"*\
*"Increase max tokens to 2000 for longer responses"*\
*"Add top\_p=0.9 to reduce repetition"*

## Editing Flows

### Structural changes

**Adding nodes:**

*"Add a validation Action before processing"*\
*"Insert a logging step after each Action"*\
*"Add an error handler at the end"*

**Removing nodes:**

*"Remove the deprecated transform\_data Action"*\
*"Delete the unused notification step"*

**Reordering:**

*"Swap the order of validation and normalization"*\
*"Move the notification to happen before storage, not after"*

### Converting serial to parallel

**You:** *"Make this Flow process items in parallel instead of sequentially"*

**Triton restructures:**

Before:

```
Input → process_item_1 → process_item_2 → process_item_3 → Output
```

After:

```
Input → [parallel]
          → process_item_1 ↘
          → process_item_2 → [merge] → Output
          → process_item_3 ↗
```

### Adding conditional logic

**You:** *"Route premium users to enhanced\_process and regular users to standard\_process"*

**Triton adds:**

```
Input → check_user_tier → [premium] → enhanced_process → Output
                        → [regular] → standard_process → Output
```

### Error handling in Flows

*"Add error routing so failed items go to a retry queue"*\
*"If validation fails, log the error and continue with the next item"*\
*"Add a fallback path if the primary API is down"*

## Editing entire Projects

### High-level modifications

**Feature additions:**

*"Add rate limiting to this Project"*\
*"Add authentication checks"*\
*"Implement caching throughout"*\
*"Add comprehensive logging"*

**Architectural changes:**

*"Split this monolithic Flow into three smaller sub-Flows"*\
*"Move all validation logic into a dedicated validation Flow"*\
*"Create a shared error handling Flow that all components use"*

**Performance improvements:**

*"Optimize this Project to handle 10x more requests"*\
*"Reduce the number of API calls"*\
*"Add batching to reduce execution time"*

### Refactoring for reusability

**You:** *"Extract the email sending logic so other Projects can use it"*

**Triton:**

1. Creates a new Action: `send_email`
2. Extracts the logic from the current Flow
3. Replaces inline logic with the new Action
4. Updates dependencies

Now multiple Projects can use `send_email`.

## Contextual editing

Triton understands your Project context when editing.

### Editing multiple related components

**You:** *"Update all Actions to use the new error logging format"*

**Triton:**

1. Scans all Actions in the Project
2. Identifies logging statements
3. Updates each one consistently
4. Reports what was changed

### Maintaining consistency

**You:** *"Make this new Action follow the same patterns as my existing ones"*

**Triton:**

* Reviews your existing Actions
* Matches coding style
* Uses same error handling approach
* Follows same naming conventions

### Bulk edits

**You:** *"Add a timeout parameter to all Actions that make API calls"*

**Triton:**

* Finds all relevant Actions
* Adds `timeout` parameter to each
* Updates function signatures
* Sets reasonable defaults

## Iterative refinement

Edit through conversation:

### Iteration example

**You:** *"Create an Action that fetches user data"*\
**Triton:** \[Creates basic Action]

**You:** *"Add caching"*\
**Triton:** \[Adds cache logic]

**You:** *"Cache should expire after 5 minutes"*\
**Triton:** \[Adds TTL]

**You:** *"Add logging when cache hits vs misses"*\
**Triton:** \[Adds logging]

**You:** *"Handle the case where the user doesn't exist"*\
**Triton:** \[Adds not-found handling]

Each iteration builds on the previous changes.

## Editing with constraints

Give Triton constraints to guide edits:

**Performance:**

* *"Optimize this, but keep it under 100ms"*
* *"Reduce API calls without changing functionality"*

**Compatibility:**

* *"Update this but maintain backward compatibility"*
* *"Migrate to the new API while supporting the old one"*

**Style:**

* *"Refactor this to follow PEP 8"*
* *"Make this more Pythonic"*

**Safety:**

* *"Add input sanitization but don't break existing tests"*
* *"Improve error handling without changing output format"*

## Reviewing Triton's edits

Always review changes:

1. **Check the diff** — What exactly changed?
2. **Test the component** — Does it still work?
3. **Verify edge cases** — Does it handle errors properly?
4. **Review new dependencies** — Are they necessary and safe?

If something's not right:

* *"Undo that change"*
* *"That broke the validation, please fix"*
* *"Actually, let's try a different approach"*

## Best practices for editing

> **Be specific** — *"Add error handling"* is vague; *"Add try-catch for JSON decode errors"* is clear

> **Test after edits** — Always run Execute to verify changes work

> **Edit incrementally** — One change at a time is easier to debug

> **Explain why** — *"Add caching because this API is rate-limited"* gives Triton better context

> **Review before deploying** — Changes look different in production

## Common editing scenarios

### Scenario: Action is failing in production

**Diagnosis:** *"Execution #1234 failed. What's wrong?"*

**Triton identifies:** Timeout error on API call

**Fix:** *"Add retry with exponential backoff and increase timeout to 30s"*

**Triton edits:** Adds tenacity retry decorator, increases timeout

**Verify:** Test with Execute, redeploy

### Scenario: Agent responses are too verbose

**Problem:** *"This Agent is writing essays instead of concise answers"*

**Fix:** *"Update the prompt to limit responses to 2-3 sentences"*

**Triton edits:** Adds constraint to system prompt

**Verify:** Test with sample inputs

### Scenario: Flow is too slow

**Problem:** *"This Flow takes 30 seconds to process 50 items"*

**Analysis:** *"Why is it slow?"*

**Triton identifies:** Sequential processing of independent items

**Fix:** *"Convert to parallel processing"*

**Triton edits:** Restructures Flow for parallel execution

**Result:** Processing time drops to \~5 seconds

## Advanced editing techniques

### Conditional edits

*"If the Action uses requests, add retry logic"*\
*"For all Agents that use tools, add tool usage examples in the prompt"*

### Pattern-based edits

*"Find all places where we call external APIs and add timeout handling"*\
*"Update all validation Actions to return structured error objects"*

### Version-based edits

*"Create a v2 of this Agent with the improvements, but keep v1 for now"*\
*"Update all components to use the new API, but create a flag to fall back to the old one"*
