Skip to content

feat(prompts): add async prompt loading#537

Open
Abhijeet Prasad (AbhiPrasad) wants to merge 1 commit into
mainfrom
abhi-async-prompt
Open

feat(prompts): add async prompt loading#537
Abhijeet Prasad (AbhiPrasad) wants to merge 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"),
)

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.
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

1 participant