Skip to content

Commit c2d36d4

Browse files
jayhackcodegen-bot
andauthored
docs: adds function call parameter helpers (#95)
# Motivation <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [ ] I have added tests for my changes - [ ] I have updated the documentation or added new documentation as needed - [x] I have read and agree to the [Contributor License Agreement](../CLA.md) --------- Co-authored-by: codegen-bot <[email protected]>
1 parent 0dc3580 commit c2d36d4

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

docs/building-with-codegen/function-calls-and-callsites.mdx

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,17 @@ def process_data(input_data: str, debug: bool = False):
7474
process_data("test", debug=True)
7575
```
7676

77-
You can access the arguments and parameters of the function call:
77+
You can access and modify the arguments and parameters of the function call with APIs detailed below.
78+
79+
### Finding Arguments
80+
81+
The primary APIs for finding arguments are:
82+
83+
- [FunctionCall.args](/api-reference/core/FunctionCall#args)
84+
- [FunctionCall.get_arg_by_parameter_name(...)](/api-reference/core/FunctionCall#get-arg-by-parameter-name)
85+
- [FunctionCall.get_arg_by_index(...)](/api-reference/core/FunctionCall#get-arg-by-index)
7886

7987
```python
80-
# Manipulation code:
8188
# Get the function call
8289
call = file.function_calls[0]
8390

@@ -98,6 +105,53 @@ debug_arg = call.get_arg_by_parameter_name("debug")
98105
first_arg = call.get_arg_by_index(0)
99106
```
100107

108+
### Modifying Arguments
109+
110+
There are two ways to modify function call arguments:
111+
112+
1. Using [FunctionCall.set_kwarg(...)](/api-reference/core/FunctionCall#set-kwarg) to add or modify keyword arguments:
113+
114+
```python
115+
# Modifying keyword arguments
116+
call.set_kwarg("debug", "False") # Modifies existing kwarg
117+
call.set_kwarg("new_param", "value", create_on_missing=True) # Adds new kwarg
118+
call.set_kwarg("input_data", "'new_value'", override_existing=True) # Converts positional to kwarg
119+
```
120+
121+
2. Using [FuncionCall.args.append(...)](/api-reference/core/FunctionCall#args) to add new arguments:
122+
<Tip>
123+
[FunctionCall.args](/api-reference/core/FunctionCall#args) is a
124+
[Collection](/building-with-codegen/collections) of
125+
[Argument](/api-reference/core/Argument) objects, so it supports
126+
[.append(...)](/api-reference/core/List#append),
127+
[.insert(...)](/api-reference/core/List#insert) and other collection
128+
methods.
129+
</Tip>
130+
131+
```python
132+
# Adding new arguments
133+
call.args.append('cloud="aws"') # Add a new keyword argument
134+
call.args.append('"value"') # Add a new positional argument
135+
136+
# Real-world example: Adding arguments to a decorator
137+
@app.function(image=runner_image)
138+
def my_func():
139+
pass
140+
141+
# Add cloud and region if not present
142+
if "cloud=" not in decorator.call.source:
143+
decorator.call.args.append('cloud="aws"')
144+
if "region=" not in decorator.call.source:
145+
decorator.call.args.append('region="us-east-1"')
146+
```
147+
148+
The `set_kwarg` method provides intelligent argument manipulation:
149+
150+
- If the argument exists and is positional, it converts it to a keyword argument
151+
- If the argument exists and is already a keyword, it updates its value (if override_existing=True)
152+
- If the argument doesn't exist, it creates it (if create_on_missing=True)
153+
- When creating new arguments, it intelligently places them based on parameter order
154+
101155
Arguments and parameters support safe edit operations like so:
102156

103157
```python

docs/introduction/about.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ iconType: "solid"
1313

1414
## Our Mission
1515

16-
Our mission is to build level-5 autonomous software engineering - the equivalent of self-driving cars for code.
16+
Our mission is to build fully-autonomous software engineering - the equivalent of self-driving cars for code.
17+
18+
We believe the highest leverage path to autonomous development is enabling AI agents to "act via code."
1719

18-
We believe the highest leverage path to autonomous development is by enabling AI agents to "act via code."
1920
Just as self-driving cars need sophisticated sensors and controls to navigate the physical world, AI agents need powerful, precise tools to manipulate codebases. We're building that foundational layer: a programmatic interface that lets AI agents express complex code transformations through code itself.
2021

2122
This approach creates a shared language that both humans and AI can use to:

0 commit comments

Comments
 (0)