Skip to content

feat(prompts): add async prompt loading#537

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi-async-prompt
Jun 30, 2026
Merged

feat(prompts): add async prompt loading#537
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi-async-prompt

Conversation

@AbhiPrasad

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) commented Jun 29, 2026

Copy link
Copy Markdown
Member

resolves #28

Add an awaitable prompt-loading API that mirrors load_prompt() while resolving prompt metadata off the event loop:

prompt = await braintrust.load_prompt_async(project="My Project", slug="my-prompt")
kwargs = prompt.build(name="Ada")

The API can be used with asyncio.gather() to load multiple prompts without blocking the event loop:

prompt_a, prompt_b = await asyncio.gather(
    braintrust.load_prompt_async(project="My Project", slug="prompt-a"),
    braintrust.load_prompt_async(project="My Project", slug="prompt-b"),
)

app_url=app_url,
api_key=api_key,
org_name=org_name,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add some kind of assertion or unit test to ensure load prompt and its async counterpart take identical arguments? thinking of cases where someone adds a new arg type to load_prompt and forgets to update the async fn

Add an awaitable prompt-loading API that mirrors `load_prompt()` while resolving
prompt metadata off the event loop:

```python
prompt = await braintrust.load_prompt_async(project="My Project", slug="my-prompt")
kwargs = prompt.build(name="Ada")
```

The API can be used with `asyncio.gather()` to load multiple prompts without
blocking the event loop:

```python
prompt_a, prompt_b = await asyncio.gather(
    braintrust.load_prompt_async(project="My Project", slug="prompt-a"),
    braintrust.load_prompt_async(project="My Project", slug="prompt-b"),
)
```

The async API reuses the existing sync `load_prompt()` implementation so cache
and fallback behavior stay consistent, and uses `asyncio.to_thread()` to avoid
blocking callers' event loops during the synchronous HTTP/cache lookup.

Tests cover eager metadata loading and parallel `load_prompt_async()` usage.
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) merged commit 803ae7a into main Jun 30, 2026
82 checks passed
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) deleted the abhi-async-prompt branch June 30, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Async prompt loading support

2 participants