Skip to main content
Code development agent with execution, analysis, and shell tools.

Simple

Agents: 1 — Single agent with code tools handles writing and executing code.

Workflow

  1. Receive code request
  2. Generate code
  3. Execute and test
  4. Return working solution

Setup

pip install praisonaiagents praisonai
export OPENAI_API_KEY="your-key"

Run — Python

from praisonaiagents import Agent
from praisonaiagents import execute_code, analyze_code

agent = Agent(
    name="Programmer",
    instructions="You are a programming agent. Write and execute code.",
    tools=[execute_code, analyze_code]
)

result = agent.start("Write a Python script to calculate fibonacci numbers")
print(result)

Run — CLI

praisonai "Write a Python function to sort a list"

Run — agents.yaml

framework: praisonai
topic: Code Development
roles:
  programmer:
    role: Software Developer
    goal: Write and execute code
    backstory: You are an expert programmer
    tools:
      - execute_code
      - analyze_code
    tasks:
      write_code:
        description: Write a Python script to calculate fibonacci numbers
        expected_output: Working Python code
praisonai agents.yaml

Serve API

from praisonaiagents import Agent
from praisonaiagents import execute_code, analyze_code

agent = Agent(
    name="Programmer",
    instructions="You are a programming agent.",
    tools=[execute_code, analyze_code]
)

agent.launch(port=8080)
curl -X POST http://localhost:8080/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Write a function to reverse a string"}'

Advanced Workflow (All Features)

Agents: 1 — Single agent with memory, persistence, structured output, and session resumability.

Workflow

  1. Initialize session for code project tracking
  2. Configure SQLite persistence for code history
  3. Generate and execute code with structured output
  4. Store code in memory for iterative development
  5. Resume session for code modifications

Setup

pip install praisonaiagents praisonai pydantic
export OPENAI_API_KEY="your-key"

Run — Python

from praisonaiagents import Agent, Task, Agents, Session
from praisonaiagents import execute_code, analyze_code
from pydantic import BaseModel

# Structured output schema
class CodeResult(BaseModel):
    language: str
    code: str
    output: str
    explanation: str

# Create session for project tracking
session = Session(session_id="code-001", user_id="user-1")

# Agent with memory and tools
agent = Agent(
    name="Programmer",
    instructions="Write, execute, and return structured code results.",
    tools=[execute_code, analyze_code],
    memory=True,
    reflection=True
)

# Task with structured output
task = Task(
    description="Write a Python script to calculate fibonacci numbers",
    expected_output="Structured code result",
    agent=agent,
    output_pydantic=CodeResult
)

# Run with SQLite persistence
agents = Agents(
    agents=[agent],
    tasks=[task],
    memory=True
)

result = agents.start()
print(result)

# Resume later
session2 = Session(session_id="code-001", user_id="user-1")
history = session2.search_memory("fibonacci")

Run — CLI

praisonai "Write fibonacci code" --memory --verbose

Run — agents.yaml

framework: praisonai
topic: Code Development
memory: true
memory_config:
  provider: sqlite
  db_path: code.db
roles:
  programmer:
    role: Software Developer
    goal: Write and execute code with structured output
    backstory: You are an expert programmer
    tools:
      - execute_code
      - analyze_code
    memory: true
    tasks:
      write_code:
        description: Write a Python script to calculate fibonacci numbers
        expected_output: Structured code result
        output_json:
          language: string
          code: string
          output: string
          explanation: string
praisonai agents.yaml --verbose

Serve API

from praisonaiagents import Agent
from praisonaiagents import execute_code, analyze_code

agent = Agent(
    name="Programmer",
    instructions="Write and execute code.",
    tools=[execute_code, analyze_code],
    memory=True
)

agent.launch(port=8080)
curl -X POST http://localhost:8080/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Write sorting code", "session_id": "code-001"}'

Monitor / Verify

praisonai "test code" --verbose

Cleanup

rm -f code.db

Features Demonstrated

FeatureImplementation
WorkflowMulti-step code development
DB PersistenceSQLite via memory_config
Observability--verbose flag
Toolsexecute_code, analyze_code
ResumabilitySession with session_id
Structured OutputPydantic CodeResult model

Next Steps