from upsonic import AutonomousAgent, Taskagent = AutonomousAgent( model="openai/gpt-4o", workspace="/path/to/project")# Execute and print resulttask = Task("Read README.md and summarize it")result = agent.print_do(task)print(result)# Or execute without printingtask = Task("Create a new file called hello.py with a hello world program")result = agent.print_do(task)print(result)
The agent handles complex long tasks automatically:
Copy
from upsonic import AutonomousAgent, Taskagent = AutonomousAgent( model="openai/gpt-4o", workspace="/path/to/project")task = Task("""1. Create a new directory called 'src'2. Create a Python file 'src/main.py' with a simple Flask app3. Create a requirements.txt with Flask as a dependency4. List all created files""")# The agent will use multiple tools to complete this taskresult = agent.print_do(task)
from upsonic import AutonomousAgent, Taskagent = AutonomousAgent( model="openai/gpt-4o", workspace="/path/to/project")# Read a filetask = Task("Read the config.py file and explain its settings")agent.print_do(task)# Edit a file (agent will read first, then edit)task = Task("Update the DEBUG setting to False in config.py")agent.print_do(task)# Search filestask = Task("Find all files that import the 'requests' library")agent.print_do(task)
from upsonic import AutonomousAgent, Taskagent = AutonomousAgent( model="openai/gpt-4o", workspace="/path/to/project", shell_timeout=10 # 60 second timeout)# Run commandstask = Task("run a shell command that waits 120 seconds")agent.print_do(task)
from upsonic import AutonomousAgent, Taskagent = AutonomousAgent( model="openai/gpt-4o", workspace="/path/to/project")task = Task("Count lines of code in all Python files")result = agent.print_do(task)# Get the run output with metadatarun_output = agent.get_run_output()if run_output: print(f"Output: {run_output.output}") print(f"Tool calls: {run_output.tool_call_count}") print(f"Status: {run_output.status}")
Session memory is enabled by default, so the agent remembers context between tasks:
Copy
from upsonic import AutonomousAgent, Taskagent = AutonomousAgent( model="openai/gpt-4o", workspace="/path/to/project" # full_session_memory=True is the default)# First tasktask = Task("Read the user model in models/user.py")agent.print_do(task)# Second task - agent remembers the previous contexttask = Task("Add an 'email' field to that user model")agent.print_do(task)# Get session usageusage = agent.get_session_usage()print(f"Total tokens used: {usage.total_tokens}")