> For the complete documentation index, see [llms.txt](https://underdogcowboy.gitbook.io/underdogcowboy-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://underdogcowboy.gitbook.io/underdogcowboy-docs/basics/interactive-agent-development.md).

# Interactive Agent Development

## Interactive Agent Development: Seamless Transitions Between Script Execution and Dialog Refinement

### Creating and Importing Agents

Users can create agents using the timeline editor CLI script. After engaging in a dialogue with an LLM through the timeline editor, users can save this interaction as an agent. Once saved, the agent becomes readily available for use in Python scripts that utilize the underdogcowboy library.

To incorporate an agent into your scripts, use the following import statement:

```python
from underdogcowboy import adm, gitbookdoc
```

### Basic Agent Interaction

With the import in place, we can program our script to communicate with the agent:

```python
# Enable dialogue with the agent via the Agent Dialog Manager (adm)
adm | [gitbookdoc]

# Send a simple message to the agent (the LLM)
response = gitbookdoc >> "Hi my friend, ready for making some documentation?"
print(response)
```

When executed, this script displays the agent's response in the console or CLI. While it ends after a single interaction, it serves as an excellent starting point for more complex development.

### Enhancing Agent Interactions

To take this further, we can transform the script into an interactive experience, allowing for extended dialogues and more dynamic interactions. Here's how we might evolve our script:

1. Implement a loop to keep the conversation going
2. Add user input functionality for back-and-forth communication
3. Include a mechanism to gracefully exit the conversation

This approach enables us to:

* Explore ideas more thoroughly
* Test the agent's responses to various inputs
* Simulate real-world interactions more closely

### Activating Interactive Mode

To achieve this enhanced interaction, simply add the following line to your script:

```python
+adm
```

The `+adm` command activates the Dialog Manager's interactive mode, which is particularly useful for developing and refining agent interactions.

### Key Features of Interactive Mode

1. **Interactive Environment**: Pauses normal script execution and opens an environment similar to the timeline editor.
2. **Continued Conversation**: Allows extended dialogue with your agent for testing and improvement.
3. **Mode Toggling**: Switch between interactive and regular command modes as needed.
4. **Resume Functionality**: Use the `resume` command to return to the normal script flow.
5. **On-the-Fly Refinement**: Improve agent responses through dialogue during development.
6. **Dynamic Updates**: The agent uses the most recent response from your dialogue when the script resumes.
7. **Iterative Development**: Run, pause, interact, improve, and resume for immediate feedback on changes.

### Benefits of Interactive Mode

* Dynamically refine agent behavior while developing your script
* Lead to more effective and tailored agent responses
* No need to modify the underlying agent definition for each improvement
* Easy way to tune agents to your standards with a simple `+adm` command

By leveraging this interactive mode, you can create more sophisticated AI-driven applications through an iterative process of development and refinement, key to building powerful, user-friendly AI tools with Underdog Cowboy.

{% hint style="info" %}
Interactive mode while working on your scripts is an easy way to get your agents more tuned to your standards. A simple +`adm` in your source will pause your script and move into interactive mode.
{% endhint %}

<figure><img src="/files/8hvLBVnyAdGbBYrNSMkl" alt=""><figcaption><p>Sample script during agent development</p></figcaption></figure>

{% @mermaid/diagram content="graph TD
A\[Timeline Editor] -->|Creates| B\[JSON File - Chat History]
B -->|Saved as| C\[an Agent]
D\[Dialog Manager adm] -->|Uses same code as| A
E\[Your Python Script] -->|Imports| C
E -->|Uses| D
D -->|Activates using: +adm| F\[Interactive Mode]
F -->|Is actually| A
F -->|Refines| C
A -->|Creates| G\[Other Agents]
E -->|Imports| G
F -->|Refines| G" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://underdogcowboy.gitbook.io/underdogcowboy-docs/basics/interactive-agent-development.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
