1
Add the 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 prefers 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.
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, Agent Stack) is responsible for providing those dependencies.
Implementing Steps
1. Add the LLM service extension to your agent
Import theLLMServiceExtensionServer and LLMServiceExtensionSpec from the SDK. You will use these within a type hint to let the platform know your agent requires LLM access.
2. Configure your LLM request
UseLLMServiceExtensionSpec.single_demand() to request a model. By passing a suggested tuple, you tell the platform which model you’d prefer to use.
"ibm/granite-3-3-8b-instruct"the platform:
- Checks if the requested model is available in your configured environment
- Allocates the best available model that matches your requirements
- Provides you with the exact model identifier and endpoint details
3. Use the LLM in your agent
Once the platform provides the extension, you can extract the OpenAI-compatible configuration.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
Full Code Example
Full Code Example
This complete example shows how to receive a user message and respond using the credentials provided by the LLM Proxy Service: