|
| 1 | +# Conversational Programming / Agent Functions |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This repository introduces a new paradigm for conversational programming using **agent functions**, which leverage GPT-based reasoning to perform semi-autonomous tasks. These functions enable flexible and intuitive operations that surpass traditional functions, especially in scenarios requiring fuzzy logic, intuition, or handling of incomplete/bad input data. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Key Concepts |
| 10 | + |
| 11 | +### **1. New Data Type: `conversation_fragment`** |
| 12 | +A `conversation_fragment` represents a segment of a GPT-powered conversation, either as input (query) or output (response). |
| 13 | +- Further categorization into **query** and **response** types. |
| 14 | +- Investigate inline tags governing conversation flow (noted by Supratik and Richard). |
| 15 | + |
| 16 | +### **2. New Class: `agent_function`** |
| 17 | +An **`agent_function`** is a GPT-powered function designed to perform a well-defined task autonomously, with minimal code and high flexibility. |
| 18 | + |
| 19 | +#### **Capabilities:** |
| 20 | +- Accepts `conversation_fragment` as input (alongside other data types). |
| 21 | +- Parses input types to construct the final query dynamically. |
| 22 | +- Produces output in the form of `conversation_fragment` or specific structured responses. |
| 23 | +- Supports **Chain of Thought** reasoning, breaking down complex problems into manageable subtasks. |
| 24 | +- Automatically logs reasoning processes for debugging and review. |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## Features & Design Principles |
| 29 | + |
| 30 | +### **Agent Function Behavior** |
| 31 | +- **Flexible Input Handling** |
| 32 | + Other input types can be parsed together at the function's start to form a structured query. |
| 33 | +- **Structured Output Formatting** |
| 34 | + Queries can specify output formats, e.g.: |
| 35 | + ```plaintext |
| 36 | + "The output should be an integer in brackets, e.g., '[2]', '[0]', etc." |
| 37 | + ``` |
| 38 | +The function then parses the structured response accordingly. |
| 39 | + |
| 40 | +### **Chain of Thought Reasoning** |
| 41 | +- Enables step-by-step problem-solving. |
| 42 | +- Automatically decomposes complex tasks into subtasks. |
| 43 | +- Summarizes reasoning and decisions for logging and debugging. |
| 44 | +- If parsing fails, retries with an extended query before throwing an exception. |
| 45 | +- Explicit handling of queries that are too long and get truncated: |
| 46 | +- Attempt to process truncated results. |
| 47 | +- Issue a follow-up query for a more concise response. |
| 48 | +- Modify the base query to request shorter responses if truncation happens frequently. |
| 49 | +- Special **failure assessment agent functions** can be created for critical tasks. |
| 50 | +- Cross-validation across multiple LLMs for comparison. |
| 51 | + |
| 52 | +### **Retrieval-Augmented Generation (RAG)** |
| 53 | +- Built-in support for both **web retrieval** and **user-defined databases**. |
| 54 | + |
| 55 | +### **Failure Rate Analysis & Statistics** |
| 56 | +- Failure rate tracking built into `agent_function` class. |
| 57 | +- Automatic failure categorization (potentially GPT-assisted). |
| 58 | +- GPT-based auto-correction of queries based on failure rate and type. |
| 59 | +- Versioned statistics—failure rates are tracked separately for different function versions. |
| 60 | + |
| 61 | +### **LLM-Agnostic Design** |
| 62 | +- **Agent functions should generalize across multiple LLMs** without requiring code duplication. |
| 63 | + |
| 64 | +### **Decision-Making Agent Functions** |
| 65 | +Agent functions can: |
| 66 | +1. **Process data and generate results** |
| 67 | +2. **Make branching decisions to determine program flow** |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## Built-in Standard Workflows |
| 72 | + |
| 73 | +### **Basic Tasks** |
| 74 | +- **Pick an item from a small list** (single-step decision-making) |
| 75 | +- **Correct grammatical or formatting errors** |
| 76 | + |
| 77 | +### **Advanced Chain of Thought** |
| 78 | +1. **Reasoning step before decision-making** (standardized `conversation_fragment` structure) |
| 79 | +2. **Error correction with optional reasoning** (asks for clarification if ambiguous) |
| 80 | +3. **Simple True/False decision-making** (with reasoning) |
| 81 | +4. **Pick an item from a list with reasoning** |
| 82 | +5. **Process a large dataset item-by-item with reasoning**, including: |
| 83 | + - Categorization |
| 84 | + - Summarization |
| 85 | + - Other forms of processing |
| 86 | + |
| 87 | +### **Retrieval-Augmented Generation (RAG)** |
| 88 | +- Intelligent selection of retrieval sources based on short previews. |
| 89 | +- Summarization and compression of retrieved content for more efficient use. |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## TODO List |
| 94 | + |
| 95 | +### **New Features to Implement** |
| 96 | +- **`BranchingConversation` class** for managing multi-step agent-driven dialogues. |
| 97 | +- **Versioning system** for conversation fragments and agent functions: |
| 98 | +- Every function using conversation fragments should be versioned. |
| 99 | +- Support calling specific function versions. |
| 100 | +- Ability to compare performance across multiple versions. |
| 101 | +- Reduce code duplication while integrating versioning across multiple functions. |
| 102 | +- **Integrate system messages into generated prompts**. |
| 103 | +- **Add notes/history fields** to conversations/fragments: |
| 104 | +- Track edits, transformations, agent interactions, and lineage. |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +## Existing Technologies & References |
| 109 | + |
| 110 | +- **OpenAI Function Calling & Assistants API** |
| 111 | +[Everything You Need to Know](https://medium.com/the-modern-scientist/everything-you-need-to-know-about-openai-function-calling-and-assistants-api-55c02570a21c) |
| 112 | +- **Agenta: Open-Source LLMOps Platform** |
| 113 | +[https://agenta.ai/](https://agenta.ai/) |
| 114 | +- **Pezzo: Open-Source AI Developer Platform** |
| 115 | +[https://github.com/pezzolabs/pezzo](https://github.com/pezzolabs/pezzo) |
0 commit comments