A small Framework built on top of openai agents sdk to develop one prompt autonomous agents
Project description
One-Prompt Agents
One-Prompt Agents is a lightweight framework for creating and running AI agents with remarkable simplicity. The core idea is that an AI agent can be defined with just two key components:
- A prompt file: Contains the natural language instructions for the agent.
- A JSON configuration file: Defines the agent's behavior, tools, and output structure.
This approach makes it easy to quickly prototype, test, and deploy AI agents for various tasks.
Core Concept: Simplicity in Agent Definition
The framework's strength lies in its straightforward approach to defining agents. Each agent is self-contained within its own directory and primarily consists of a prompt and a configuration file.
Directory Structure
All agents reside within a main directory named agents_config. This directory should be located in the root of your project, from where you'll run the main application.
Each agent has its own subdirectory within agents_config:
your-project-root/
├── agents_config/
│ ├── AgentName1/
│ │ ├── config.json
│ │ ├── prompt.txt
│ │ └── return_type.py (optional)
│ └── AgentName2/
│ ├── config.json
│ ├── another_prompt.md
│ └── return_type.py (optional)
└── src/
└── one_prompt_agents/
└── main.py
Key Components
Inside each agent's directory (e.g., AgentName1), you'll find:
-
config.json: This is the heart of the agent's definition.name(string): The unique name of the agent. This name is used to identify and call the agent.prompt_file(string): The filename of the text file containing the agent's core prompt (e.g., "prompt.txt", "instructions.md").return_type(string, optional): The name of a Pydantic model class defined inreturn_type.py. If this field is omitted or thereturn_type.pyfile is absent/empty, the framework will create a minimal model automatically and the selected prompt-strategy will augment it with any fields it needs.inputs_description(string): A human-readable description of what inputs the agent expects. This helps in understanding how to interact with the agent.tools(list of strings): A list of other agents or pre-defined MCP (Multi-Capability Agent Protocol) server names that this agent can utilize as tools. If the agent doesn't use any tools, this can be an empty list[].model(string, optional): Specifies the underlying language model to be used (e.g., "o4-mini", "gpt-4"). If omitted, a default model (currently "o4-mini") is used.
-
Prompt File (e.g.,
prompt.txt,another_prompt.md):- This is a plain text or markdown file containing the natural language instructions, persona, and context for the AI agent. The content of this file will guide the agent's behavior and responses.
-
return_type.py(optional):- If present, this Python file defines a Pydantic model corresponding to the
return_typestring (if provided) inconfig.json. - Providing your own model lets you enforce additional structure in the agent's output. When the file is missing the framework falls back to an empty model, which strategies will extend as necessary at runtime.
Example
return_type.py:from pydantic import BaseModel, Field from typing import List class AnalysisResult(BaseModel): summary: str = Field(description="A brief summary of the analysis.") keywords: List[str] = Field(description="A list of extracted keywords.") confidence: float = Field(description="A confidence score for the analysis.")
In this example, the
config.jsonfor this agent would have"return_type": "AnalysisResult". - If present, this Python file defines a Pydantic model corresponding to the
System Requirements
- Python: Version 3.8 or higher.
- pip: Python package installer (usually comes with Python).
- git: For cloning the repository.
API Keys
This application interacts with OpenAI services and requires an OPENAI_API_KEY environment variable to be set.
Please ensure you have this environment variable configured with your valid OpenAI API key before running the application.
For example:
export OPENAI_API_KEY='your_openai_api_key_here'
The application will not function correctly without this key.
Installation
-
Clone the repository:
git clone https://github.com/your-username/one-prompt-agents.git # Replace with the actual repository URL cd one-prompt-agents
-
Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
Creating Your First Agent: An "EchoAgent" Example
Let's illustrate how simple it is to create an agent. We'll make an "EchoAgent" that simply returns the prompt it receives.
-
Create the agent's directory structure:
First, ensure you have the main
agents_configdirectory in your project root. Then, create a directory for your new agent:your-project-root/ ├── agents_config/ │ └── EchoAgent/ # Create this directory │ ├── config.json # We'll create this file │ ├── prompt.txt # We'll create this file │ └── return_type.py # We'll create this file └── ... (other project files) -
Create the
config.jsonfile:Create
agents_config/EchoAgent/config.jsonwith the following content:{ "name": "EchoAgent", "prompt_file": "prompt.txt", "return_type": "EchoResponse", "inputs_description": "Any text prompt that the agent will echo back in the 'content' field.", "tools": [], "model": "o4-mini" }
-
Create the
prompt.txtfile:Create
agents_config/EchoAgent/prompt.txtwith the following content:You are an Echo Agent. Your sole purpose is to return the exact text provided to you by the user. The user's text will be provided as input. You must return this text in the 'content' field of your response. Do not add any extra information, explanations, or greetings. Just echo the input into the 'content' field.
-
Create the
return_type.pyfile:Create
agents_config/EchoAgent/return_type.pywith the following content:from pydantic import BaseModel, Field class EchoResponse(BaseModel): content: str = Field(description="The exact text that was provided in the prompt.")
And that's it! You've defined a simple agent. The framework will load this agent based on these files. The EchoResponse model ensures that the output will be a JSON object with a content field.
Running Agents
Once you have defined your agents in the agents_config directory (located at the root of your project), you can run them using the commands configured in pyproject.toml. Ensure your project's virtual environment is activated to use these commands.
1. Interactive REPL Mode
This mode allows you to chat with a specific agent directly in your console. The agent's textual response is typically expected to be found in a content field of its structured JSON output.
- Start REPL:
run_agent <agent_name>Example:run_agent EchoAgentYou'll be prompted for input, and the agent will respond. If the agent'sreturn_type.pydefines acontentfield, that's what will be displayed as the primary response.
2. Autonomous Console Mode
This mode runs an agent with a single prompt directly from the command line and typically prints its full structured output (or a summary, depending on agent design).
- Run agent:
run_agent <agent_name> "<your_prompt_here>"
Example:run_agent EchoAgent "Hello from the console!"
3. HTTP Server Mode
This mode starts a FastAPI server, allowing you to interact with your agents via HTTP requests.
-
Start the server:
run_server
By default, the server runs on
http://127.0.0.1:9000. You might see logging options likerun_server --log -vif you need more detailed output or file logging, similar to the previouspython -m src.one_prompt_agents.main --log -v. -
Triggering an agent: Send a
POSTrequest to the/{agent_name}/runendpoint. The body of the request should be a JSON object containing the prompt. For example, to run ourEchoAgent:curl -X POST http://127.0.0.1:9000/EchoAgent/run -H "Content-Type: application/json" -d '{"prompt": "Hello, world!"}'
The agent will process the request asynchronously. The immediate response will be:
{"status": "started", "agent": "EchoAgent"}
The actual output of the agent (the echoed text in this case) will be processed in the background.
-
Helper Script (
http_start.py): The project includes a helper scripthttp_start.pythat ensures the server is running (starting it if necessary) and then triggers an agent. This script still usespython -m ...as it's a standalone utility.python -m src.one_prompt_agents.http_start <agent_name> "<your_prompt_here>"
Example:
python -m src.one_prompt_agents.http_start EchoAgent "This is a test prompt."
Important: Remember that the agents_config directory, containing all your agent definitions, must be present in the directory from which you execute these commands.
Advanced Strategy: The "Make a Plan" Approach
For more complex tasks that require multiple steps or objectives, agents can be designed to first create a plan and then execute it. This strategy enhances the agent's autonomy and allows for better progress tracking, especially in autonomous scenarios.
Core Idea
Instead of directly trying to solve the entire task with a single response, the agent's initial goal is to outline a series of steps (a plan) to achieve the overall objective.
-
Define a Plan-Oriented
return_type: The agent'sreturn_type.pywould define Pydantic models representing the plan and its individual tasks. Each task could have attributes like a description and a completion status (e.g., "pending", "completed").Example
return_type.pyfor a planning agent:from pydantic import BaseModel, Field from typing import List class Task(BaseModel): task_id: int = Field(description="Unique identifier for the task.") description: str = Field(description="What needs to be done for this task.") status: str = Field(default="pending", description="Status of the task, e.g., 'pending', 'completed'.") class PlanResponse(BaseModel): plan_summary: str = Field(description="A brief summary of the overall plan.") tasks: List[Task] = Field(description="A list of tasks to be executed.") next_task_id: int | None = Field(default=None, description="The ID of the next task to be executed.")
The agent's
config.jsonwould then specify"return_type": "PlanResponse". -
Prompt for Planning: The agent's prompt file (e.g.,
prompt.txt) would instruct it to analyze the user's request, break it down into manageable steps, and return this plan using the definedPlanResponsestructure. -
Interaction Flow:
- User: Provides an initial complex prompt (e.g., "Research topic X and write a summary").
- Agent (First Interaction): Returns a
PlanResponseJSON object detailing the steps (e.g., Task 1: Search for sources, Task 2: Read and analyze sources, Task 3: Draft summary, Task 4: Review and finalize summary). Initially, all tasks are "pending". - User/Orchestrator: Reviews the plan. Then, in subsequent turns, instructs the agent to execute the plan, often step-by-step (e.g., "Proceed with the next step", "Execute task 2").
- Agent (Subsequent Interactions): Executes the indicated task. It might return an updated
PlanResponseshowing the completed task and potentially the output of that specific task, or a simpler status update. It might also update thenext_task_id.
Benefits
- Handles Complex Goals: Breaks down large tasks into smaller, manageable parts.
- Transparency & Control: Users can see the agent's plan before execution and guide the process.
- Progress Tracking: Easy to see which steps have been completed and what's next.
- Flexibility: Allows for iterative execution and potential plan adjustments if needed.
This "make a plan" strategy is particularly effective for autonomous agents designed to perform multi-stage operations. For interactive agents, the core idea of returning a structured response (like the content field in the EchoAgent) remains the primary mode of simple interaction, but more complex interactive agents could also adopt planning for guided task completion.
Logging
The main.py script provides options to control logging:
--log: If this flag is present, logs will be redirected to a file (e.g.,mcp.log).-vor--verbose: Enables verbose output by setting the logging level to DEBUG. This is useful for troubleshooting and understanding the agent's internal operations.
Example of running the server with verbose logging to a file:
python -m src.one_prompt_agents.main --log -v
Advanced: Agent Tools and Dependencies
Agents can be designed to use other agents or pre-defined MCP (Multi-Capability Agent Protocol) servers as "tools." This allows you to build more complex systems where agents can delegate specific tasks to specialized tools or other agents.
This is configured in an agent's config.json file using the tools field:
{
"name": "MyMainAgent",
"prompt_file": "main_prompt.txt",
"return_type": "MainResponse",
"inputs_description": "Input for the main agent.",
"tools": ["AnotherAgentName", "SomeMCPTool"], // Names of other agents or MCP servers
"model": "o4-mini"
}
In this example, MyMainAgent would have access to AnotherAgentName (which must also be defined in the agents_config directory) and SomeMCPTool (which should be a pre-configured MCP server known to the system). The prompt for MyMainAgent would then instruct it on how and when to use these tools.
The framework handles the resolution and communication with these declared tools.
Extending with Custom MCP Servers
Beyond using other agents as tools, the framework supports the integration of custom MCP (Multi-Capability Agent Protocol) servers. This allows you to connect specialized, independently running services or capabilities that adhere to the MCP standard. The mcp_servers_loader.py module is responsible for discovering and loading these custom MCP servers.
How it Works
-
Directory for MCP Servers:
- Create a directory in your project, conventionally named
mcp_servers/(this is configurable viaSEARCH_DIRinmcp_servers_loader.py). This directory will house your custom MCP server definitions.
- Create a directory in your project, conventionally named
-
MCP Server Definition Files:
- Inside the
mcp_servers/directory, create Python files for each of your custom MCP servers. - These files must have a specific suffix, by default
_mcp_server.py(configurable viaMODULE_SUFFIXinmcp_servers_loader.py). For example,my_custom_tool_mcp_server.py.
- Inside the
-
Defining MCP Server Instances:
- Within each such Python file, define one or more module-level instances of
MCPServerSseorMCPServerStdio(fromagents.mcp). These are the classes that represent your MCP server's client-side interface. - Each instance must have a unique
nameattribute. This name is how agents will refer to this MCP server in theirtoolslist inconfig.json.
Example
mcp_servers/apify_example_mcp_server.py:import os import sys from pathlib import Path from agents.mcp import MCPServerStdio, MCPServerSse from types import MethodType # --- NEW: Apify SSE server --- APIFY_TOKEN = os.getenv("APIFY_TOKEN") if not APIFY_TOKEN: sys.exit("❌ export APIFY_TOKEN first") apify_server = MCPServerSse( params={ "url": f"https://actors-mcp-server.apify.actor/sse?enableAddingActors=true", # "headers": { "Authorization": f"Bearer {APIFY_TOKEN}", # Apify also accepts this custom header, either is fine: # "x-apify-token": APIFY_TOKEN, }, "timeout": 180, "sse_read_timeout": 300, }, client_session_timeout_seconds=60, cache_tools_list=True, name="apify-mcp-server", )
- Within each such Python file, define one or more module-level instances of
-
Automatic Discovery and Loading:
- When the main application starts (via
cli.py), thecollect_servers()function frommcp_servers_loader.pyis invoked. - It scans the
SEARCH_DIR(e.g.,mcp_servers/) for files ending withMODULE_SUFFIX(e.g.,_mcp_server.py). - It dynamically imports these modules.
- It collects all top-level instances of
MCPServerSseorMCPServerStdiofound in these modules. These are made available to agents that list them in theirtools. - If a module defines a callable
main()function at the top level, it is executed. Anyasyncio.Taskreturned bymain()will be collected and managed by the main application loop, allowing your MCP server to run its own asynchronous operations if needed (e.g., starting the actual server-side component that theMCPServerSseinstance connects to).
- When the main application starts (via
Key Expectations and Features
- Naming: The
nameattribute of yourMCPServerSseorMCPServerStdioinstance is crucial. It's the identifier used in an agent'sconfig.jsontoolsarray. - Configuration (
params): Theparamsdictionary passed to theMCPServerSseorMCPServerStdioconstructor should contain all necessary information for the client to connect to and interact with your actual MCP server (e.g., URL, timeouts). - Server-Side Logic (Optional
main()hook):- The
MCPServerSse/MCPServerStdioinstances you define are clients that enable agents to talk to your MCP-compliant service. - If the actual service (the server part of your MCP tool) needs to be started or managed by the One-Prompt Agents framework itself, you can implement this logic within the optional
main()function in your*_mcp_server.pyfile. - For example,
main()could start a local FastAPI/Uvicorn server that implements the MCP tool's functionality, and theMCPServerSseinstance would point to this local server's URL.
- The
- Agent Integration: Once an MCP server is loaded, any agent can list its
namein itstoolsarray (in itsconfig.json). The framework will then inject this pre-configuredMCPServerSseorMCPServerStdioinstance into the agent, allowing the agent's prompt to delegate tasks to it.
This mechanism provides a flexible way to extend the capabilities of your agents by integrating with external or custom-built MCP-compliant tools and services.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file one_prompt_agents-0.0.2.tar.gz.
File metadata
- Download URL: one_prompt_agents-0.0.2.tar.gz
- Upload date:
- Size: 45.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a6d268cfd2ab4b8e4d7c630a3bb2fa16fbfc676184259a1b4c6594f355c5e12
|
|
| MD5 |
34125d14e9206f567db49a7f72b3f037
|
|
| BLAKE2b-256 |
fd79cb7bda2f8ad8b823fbb490ab0589e2ebfc31d71dd68bea7ecf2cadcff2b6
|
File details
Details for the file one_prompt_agents-0.0.2-py3-none-any.whl.
File metadata
- Download URL: one_prompt_agents-0.0.2-py3-none-any.whl
- Upload date:
- Size: 46.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40d9ee84cd957fc87ab1b3e096a5651853a6cc07e0b4b5c72c8c107028a0836f
|
|
| MD5 |
2a7233995934c84da2bb50757d5117da
|
|
| BLAKE2b-256 |
ab92e1d12dbcd03a36058cb88e34e136151b0154810c41efcca7ce82a46a4a2c
|