Skip to main content

Agent-First Development toolkit for Python

Project description

AFD - Agent-First Development for Python

A Python toolkit for building applications with the Agent-First Development methodology.

What is AFD?

Agent-First Development is a software development methodology where AI agents are treated as first-class users from day one. Instead of building UI first and adding API/agent access later, AFD inverts this:

Traditional:  UI → API → Agent Access (afterthought)
Agent-First:  Commands → Validation → UI (surface)

Installation

# Core types only
pip install afd

# With MCP server support
pip install afd[server]

# With CLI
pip install afd[cli]

# With testing utilities
pip install afd[testing]

# Everything
pip install afd[all]

Quick Start

Define a Command

from afd import CommandResult, success, error
from afd.server import define_command
from pydantic import BaseModel

class Todo(BaseModel):
    id: str
    title: str
    done: bool = False

@define_command(
    name="todo.create",
    description="Create a new todo item",
)
async def create_todo(title: str) -> CommandResult[Todo]:
    todo = Todo(id="todo-1", title=title)
    return success(
        data=todo,
        reasoning="Created new todo with default status",
    )

Create an MCP Server

from afd.server import create_server

server = create_server(
    name="todo-app",
    version="1.0.0",
)

@server.command(
    name="todo.create",
    description="Create a todo",
)
async def create_todo(input):
    todo = Todo(id="todo-1", title=input["title"])
    return success(data=todo)

# Run the server (stdio for VS Code/Cursor)
server.run()

Test Your Commands

import pytest
from afd.testing import assert_success

# Use the mock_server fixture
async def test_create_todo(mock_server):
    @mock_server.command("todo.create")
    async def handler(input):
        from afd import success
        return success({"id": "1", "title": input["title"]})

    result = await mock_server.execute("todo.create", {"title": "Test"})

    data = assert_success(result)
    assert data["title"] == "Test"

Core Types

CommandResult

The standard return type for all commands:

from afd import CommandResult, success, error

# Successful result
result = success(
    data={"id": "123"},
    reasoning="Created successfully",
    confidence=0.95,
)

# Error result
result = error(
    code="NOT_FOUND",
    message="Resource not found",
    suggestion="Check the ID and try again",
)

UX-Enabling Fields

AFD results include optional fields that enable rich agent experiences:

Field Purpose
confidence 0-1 score for UI confidence indicators
reasoning Explains "why" for transparency
sources Attribution for verification
plan Multi-step operation visibility
alternatives Other options considered
warnings Non-fatal issues to surface

Packages

Extra Contents
(core) CommandResult, success(), error(), error types, metadata types
[server] MCP server factory, @define_command, create_server()
[cli] Click-based CLI for connecting to MCP servers
[testing] mock_server fixture, assertions, MockTransport

Related

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

afd-0.1.2.tar.gz (67.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

afd-0.1.2-py3-none-any.whl (56.2 kB view details)

Uploaded Python 3

File details

Details for the file afd-0.1.2.tar.gz.

File metadata

  • Download URL: afd-0.1.2.tar.gz
  • Upload date:
  • Size: 67.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for afd-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2db678578268d8c543dee46770234ad70e1278bdf75f83d2068f1d8838e7f397
MD5 86dc555e223e9998f768d0bbfc18135c
BLAKE2b-256 129d0fe786ab517748aecdcf00b21736a98e87ee5547c8718687d75b30712d6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for afd-0.1.2.tar.gz:

Publisher: publish-python.yml on lushly-dev/afd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file afd-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: afd-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 56.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for afd-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c57524995ccd080c22df41269aa8ceb8e8c523783447f23ee9d6a99cf881b383
MD5 4abd5fbcfa504ec3bff52c8a5ce590c0
BLAKE2b-256 09d4622a69c41c29b2f1ae56c4a5536a83664dff86d775f556f15e2f69869900

See more details on using hashes here.

Provenance

The following attestation bundles were made for afd-0.1.2-py3-none-any.whl:

Publisher: publish-python.yml on lushly-dev/afd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page