autoform
composable function transformations for LLM programs
⚠️ early development: API may change.
pip install autoform
Example
Write a multi-agent pipeline once. get per-agent semantic gradients on a batched dataset in one call.
import autoform as af
class Verdict(af.Struct): # pydantic model for structured output
decision: str
reasoning: str
def judge_debate(topic: str) -> Verdict:
"""three agents debate, one judges. we can optimize any of them."""
# agent 1: argue for
pro = af.format("Argue FOR: {}", topic)
pro = af.checkpoint(pro, collection="debug", name="pro") # tag for collection
msg = dict(role="user", content=pro)
pro = af.lm_call([msg], model="gpt-4.1")
# agent 2: argue against
con = af.format("Argue AGAINST: {}", topic)
con = af.checkpoint(con, collection="debug", name="con")
msg = dict(role="user", content=con)
con = af.lm_call([msg], model="gpt-4.1")
# agent 3: judge
prompt = af.format("PRO: {}\nCON: {}\nWho wins?", pro, con)
prompt = af.checkpoint(prompt, collection="debug", name="judge")
msg = dict(role="user", content=prompt)
return af.struct_lm_call([msg], model="gpt-4o", struct=Verdict)
# trace with a dummy input (no executions happens)
ir = af.build_ir(judge_debate)("...")
# execute
verdict = af.call(ir)("pineapple on pizza")
# batch: parallel topics
batch = af.batch(ir, in_axes=list)
verdicts = af.call(batch)(["pineapple on pizza", "cats vs dogs", "morning vs night"])
# gradients: feedback on output -> feedback on input
pb_ir = af.pullback(ir)
feedback = Verdict(decision="too one-sided", reasoning="pro was weak")
verdict, grad = af.call(pb_ir)(("pineapple on pizza", feedback))
# batched gradients
batch_pb = af.batch(pb_ir, in_axes=(list, list))
# collect: capture intermediate values at runtime
verdict, captured = af.collect(ir, collection="debug")("pineapple on pizza")
# captured: {'pro': 'Argue FOR: ...', 'con': '...', 'judge': '...'}
# inject: override checkpoint outputs with different values
values = dict(pro="custom argument")
verdict = af.inject(ir, collection="debug", values=values)("pineapple on pizza")
# transforms compose
batch_batch = af.batch(af.batch(ir, in_axes=list), in_axes=list)
grad_grad = af.pullback(af.pullback(ir))
More
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
autoform-0.0.6.tar.gz
(42.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
autoform-0.0.6-py3-none-any.whl
(27.3 kB
view details)
File details
Details for the file autoform-0.0.6.tar.gz.
File metadata
- Download URL: autoform-0.0.6.tar.gz
- Upload date:
- Size: 42.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6e2f9bb5b2dd23ac98aeef9c9ea808cdf43839b428828277442001c6aa03380
|
|
| MD5 |
c76fbdb77f645cdf12cc4b9a58322411
|
|
| BLAKE2b-256 |
bc0e0dc2f607df2f6cb3b26467c84bdab858c9bca59662dcc22a9cdf0ab7affc
|
File details
Details for the file autoform-0.0.6-py3-none-any.whl.
File metadata
- Download URL: autoform-0.0.6-py3-none-any.whl
- Upload date:
- Size: 27.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3681073c98d4b042caa4972f6b9ca0ff1b16954c4b6fa6d9118e2b3d840d555d
|
|
| MD5 |
42824c8990deddb84c8727b9ba6bf3b8
|
|
| BLAKE2b-256 |
27638e19863eb74cec1e59cc47ab77103540659a1f2c022e532e78fbd2c0b992
|