You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This mechanism is also useful for tools that need additional input that cannot be supplied by the LLM, such as connections, secrets, etc.
530
530
531
+
### Compatibility: Using KernelFunction as Agent Framework tools
532
+
533
+
If you have existing Semantic Kernel code with `KernelFunction` instances (either from prompts or from methods), you can convert them to Agent Framework tools using the `.as_agent_framework_tool` method.
534
+
535
+
> [!IMPORTANT]
536
+
> This feature requires `semantic-kernel` version 1.38 or higher.
537
+
538
+
#### Using KernelFunction from a prompt template
539
+
540
+
```python
541
+
from semantic_kernel import Kernel
542
+
from semantic_kernel.functions import KernelFunctionFromPrompt
543
+
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, OpenAIChatPromptExecutionSettings
544
+
from semantic_kernel.prompt_template import KernelPromptTemplate, PromptTemplateConfig
545
+
from agent_framework.openai import OpenAIResponsesClient
546
+
547
+
# Create a kernel with services and plugins
548
+
kernel = Kernel()
549
+
# will get the api_key and model_id from the environment
response =await agent.run("What's the weather in Seattle?")
600
+
print(response.text)
601
+
```
602
+
603
+
#### Using VectorStore with create_search_function
604
+
605
+
You can also use Semantic Kernel's VectorStore integrations with Agent Framework. The `create_search_function` method from a vector store collection returns a `KernelFunction` that can be converted to an Agent Framework tool.
606
+
607
+
```python
608
+
from semantic_kernel import Kernel
609
+
from semantic_kernel.connectors.ai.open_ai import OpenAITextEmbedding
610
+
from semantic_kernel.connectors.azure_ai_search import AzureAISearchCollection
611
+
from semantic_kernel.functions import KernelParameterMetadata
612
+
from agent_framework.openai import OpenAIResponsesClient
instructions="You are a travel agent that helps people find hotels.",
668
+
tools=search_tool
669
+
)
670
+
response =await agent.run("Find me a hotel in Seattle")
671
+
print(response.text)
672
+
```
673
+
674
+
This pattern works with any Semantic Kernel VectorStore connector (Azure AI Search, Qdrant, Pinecone, etc.), allowing you to leverage your existing vector search infrastructure with Agent Framework agents.
675
+
676
+
This compatibility layer allows you to gradually migrate your code from Semantic Kernel to Agent Framework, reusing your existing `KernelFunction` implementations while taking advantage of Agent Framework's simplified agent creation and execution patterns.
677
+
531
678
## 6. Agent Non-Streaming Invocation
532
679
533
680
Key differences can be seen in the method names from `invoke` to `run`, return types (for example, `AgentRunResponse`) and parameters.
@@ -87,7 +87,210 @@ The `TextSearchProvider` class supports the following options via the `TextSearc
87
87
::: zone-end
88
88
::: zone pivot="programming-language-python"
89
89
90
-
More info coming soon.
90
+
## Using Semantic Kernel VectorStore with Agent Framework
91
+
92
+
Agent Framework supports using Semantic Kernel's VectorStore collections to provide RAG capabilities to agents. This is achieved through the bridge functionality that converts Semantic Kernel search functions into Agent Framework tools.
93
+
94
+
> [!IMPORTANT]
95
+
> This feature requires `semantic-kernel` version 1.38 or higher.
96
+
97
+
### Creating a Search Tool from VectorStore
98
+
99
+
The `create_search_function` method from a Semantic Kernel VectorStore collection returns a `KernelFunction` that can be converted to an Agent Framework tool using `.as_agent_framework_tool()`.
100
+
Use [the vector store connectors documentation](/semantic-kernel/concepts/vector-store-connectors) to learn how to set up different vector store collections.
101
+
102
+
```python
103
+
from semantic_kernel.connectors.ai.open_ai import OpenAITextEmbedding
104
+
from semantic_kernel.connectors.azure_ai_search import AzureAISearchCollection
105
+
from semantic_kernel.functions import KernelParameterMetadata
106
+
from agent_framework.openai import OpenAIResponsesClient
instructions="You are a helpful support specialist. Use the search tool to find relevant information before answering questions. Always cite your sources.",
157
+
tools=search_tool
158
+
)
159
+
160
+
# Use the agent with RAG capabilities
161
+
response =await agent.run("How do I return a product?")
162
+
print(response.text)
163
+
```
164
+
165
+
### Customizing Search Behavior
166
+
167
+
You can customize the search function with various options:
168
+
169
+
```python
170
+
# Create a search function with filtering and custom formatting
For the full details on the parameters available for `create_search_function`, see the [Semantic Kernel documentation](/semantic-kernel/concepts/vector-store-connectors/).
205
+
206
+
### Using Multiple Search Functions
207
+
208
+
You can provide multiple search tools to an agent for different knowledge domains:
209
+
210
+
```python
211
+
# Create search functions for different knowledge bases
instructions="You are a support agent. Use the appropriate search tool to find information before answering. Cite your sources.",
229
+
tools=[product_search, policy_search]
230
+
)
231
+
```
232
+
233
+
You can also create multiple search functions from the same collection with different descriptions and parameters to provide specialized search capabilities:
234
+
235
+
```python
236
+
# Create multiple search functions from the same collection
instructions="You are a support agent. Use search_all_articles for general queries and get_article_details when you need full details about a specific article.",
275
+
tools=[general_search, detail_lookup]
276
+
)
277
+
```
278
+
279
+
This approach allows the agent to choose the most appropriate search strategy based on the user's query.
280
+
281
+
### Supported VectorStore Connectors
282
+
283
+
This pattern works with any Semantic Kernel VectorStore connector, including:
284
+
285
+
- Azure AI Search (`AzureAISearchCollection`)
286
+
- Qdrant (`QdrantCollection`)
287
+
- Pinecone (`PineconeCollection`)
288
+
- Redis (`RedisCollection`)
289
+
- Weaviate (`WeaviateCollection`)
290
+
- In-Memory (`InMemoryVectorStoreCollection`)
291
+
- And more
292
+
293
+
Each connector provides the same `create_search_function` method that can be bridged to Agent Framework tools, allowing you to choose the vector database that best fits your needs. See [the full list here](/semantic-kernel/concepts/vector-store-connectors/out-of-the-box-connectors).
0 commit comments