Service Extensions are a type of A2A Extension that allows you to easily “inject dependencies” into your agent. This follows the inversion of control principle where your agent defines what it needs, and the platform (in this case, BeeAI) is responsible for providing those dependencies.
Service extensions are optional by definition, so you should always check if they exist before using them.
Quickstart
1
Add LLM service extension to your agent
Import the necessary components and add the LLM service extension to your agent function.
2
Configure your LLM request
Specify which model your agent prefer and how you want to access it.
3
Use the LLM in your agent
Access the optionally provided LLM configuration and use it with your preferred LLM client.
Example of LLM Access
Here’s how to add LLM inference capabilities to your agent:How to request LLM access
Here’s what you need to know to add LLM inference capabilities to your agent: Import the extension: ImportLLMServiceExtensionServer
and LLMServiceExtensionSpec
from beeai_sdk.a2a.extensions
.
Add the LLM parameter: Add a third parameter to your agent function with the Annotated
type hint for LLM access.
Specify your model requirements: Use LLMServiceExtensionSpec.single_demand()
to request a single model (multiple models will be supported in the future).
Suggest a preferred model: Pass a tuple of suggested model names to help the platform choose the best available option.
Check if the extension exists: Always verify that the LLM extension is provided before using it, as service extensions are optional.
Access LLM configuration: Use llm.data.llm_fulfillments.get("default")
to get the LLM configuration details.
Use with your LLM client: The platform provides api_model
, api_key
, and api_base
that work with OpenAI-compatible clients.
Understanding LLM Configuration
The platform automatically provides you with:api_model
: The specific model identifier that was allocated to your requestapi_key
: Authentication key for the LLM serviceapi_base
: The base URL for the OpenAI-compatible API endpoint
- BeeAI Framework
- LangChain
- LlamaIndex
- OpenAI Python client
- Custom implementations
Model Selection
When you specify a suggested model like"ibm/granite-3-3-8b-instruct"
, the platform will:
- Check if the requested model is available in your configured environment
- Allocate the best available model that matches your requirements
- Provide you with the exact model identifier and endpoint details