Skip to content

Improve ergonomics of Application Functions #485

@diptanu

Description

@diptanu

Claude Code and other coding agents make mistakes all the time for the application functions because it's pretty unusual for any framework to have the limitation of having exactly one input parameter as the entrypoint. We have to extend this so that the very first thing an agent writes doesn't lead to an error.

Current Behavior

Application functions currently require exactly one parameter (the request input). The following patterns are not supported:

# Multiple parameters 
@application()
@function()
def process_order(item: Item, user: dict, importance: int) -> str:
    ...

# No parameters 
@application()
@function()
def health_check() -> str:
    return "OK"

Users must wrap all inputs into a single object:

class ProcessOrderRequest(BaseModel):
    item: Item
    user: dict
    importance: int

@application()
@function()
def process_order(request: ProcessOrderRequest) -> str:
    ...

Proposed Behavior

Allow application functions to accept zero, one, or multiple parameters, mapping them to a JSON request body:

Multiple parameters

@application()
@function()
def process_order(item: Item, user: dict, importance: int) -> str:
    ...

Request body:

{
    "item": {
        "name": "Foo",
        "description": "The pretender",
        "price": 42.0,
        "tax": 3.2
    },
    "user": {
        "username": "dave",
        "full_name": "Dave Grohl"
    },
    "importance": 5
}

Single parameter (backward compatible)

@application()
@function()
def create_item(item: Item) -> str:
    ...

Request body:

{
    "name": "Foo",
    "description": "The pretender",
    "price": 42.0,
    "tax": 3.2
}

No parameters

@application()
@function()
def health_check() -> str:
    return "OK"

Request body: {} or no body required

This follows the convention how FastAPI handles body of requests.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions