AgentRecommendationWorkflow
What it is
A workflow that recommends AI agents (models/providers) based on a natural-language intent by:
- selecting a SPARQL query template from a TTL file,
- templating it with user constraints (scores, cost, provider, result limit),
- executing it against an Oxigraph SPARQL endpoint,
- formatting the bindings into a structured list of recommendations.
Public API
Classes
-
AgentRecommendationConfiguration(WorkflowConfiguration)- Purpose: Configure where to load SPARQL templates from and where to execute them.
- Fields:
triple_store: ITripleStoreService(currently not used in this module’s logic)oxigraph_url: str(default:http://localhost:7878)queries_file_path: str(default:src/core/modules/abi/ontologies/application-level/AgentRecommendationSparqlQueries.ttl)
-
AgentRecommendationParameters(WorkflowParameters)- Purpose: Provide runtime inputs for generating recommendations.
- Fields:
intent_description: str(required)min_intelligence_score: Optional[int](default:10)max_input_cost: Optional[float](default:None)max_results: Optional[int](default:10)provider_preference: Optional[str](default:None)
-
AgentRecommendationWorkflow(Workflow)- Purpose: Load query templates, match intent, execute SPARQL, and return recommendations.
Methods (AgentRecommendationWorkflow)
-
__init__(configuration: AgentRecommendationConfiguration)- Loads query templates from
queries_file_pathat initialization.
- Loads query templates from
-
run_workflow(parameters: WorkflowParameters) -> Dict[str, Any]- Executes the end-to-end recommendation process.
- Returns a dict with:
intentquery_used(the matched template’s intent description)recommendations(list of formatted recommendations)total_found
-
as_tools() -> list[BaseTool]- Exposes the workflow as a LangChain
StructuredTool:- name:
recommend_ai_agents - args schema:
AgentRecommendationParameters
- name:
- Exposes the workflow as a LangChain
-
as_api(...) -> None- Present but does nothing (returns
None).
- Present but does nothing (returns
-
get_configuration() -> AgentRecommendationConfiguration- Returns the workflow configuration.
Configuration/Dependencies
External services
- Oxigraph SPARQL endpoint: the workflow POSTs queries to:
POST {oxigraph_url}/query- Header:
Content-Type: application/sparql-query - Expects a JSON response shaped like SPARQL results (
results.bindings).
Files
- TTL file with SPARQL templates:
queries_file_pathmust exist.- Parsed via
rdflib.Graph.parse(..., format="turtle"). - Query templates are extracted using the
INTENT_MAPPINGpredicates:intentMapping:intentDescriptionintentMapping:sparqlTemplate
- Parsed via
Python dependencies (imports used)
requestsrdfliblangchain_core.tools(BaseTool,StructuredTool)naas_abi_coreworkflow and router types
Usage
from naas_abi.workflows.AgentRecommendationWorkflow import (
AgentRecommendationWorkflow,
AgentRecommendationConfiguration,
AgentRecommendationParameters,
)
# Provide a triple_store instance per your environment (not used by this workflow logic).
triple_store = ... # must satisfy ITripleStoreService
wf = AgentRecommendationWorkflow(
AgentRecommendationConfiguration(
triple_store=triple_store,
oxigraph_url="http://localhost:7878",
queries_file_path="path/to/AgentRecommendationSparqlQueries.ttl",
)
)
result = wf.run_workflow(
AgentRecommendationParameters(
intent_description="Need a fast and cheap model for coding",
min_intelligence_score=50,
max_input_cost=1.0,
max_results=5,
provider_preference=None,
)
)
print(result["total_found"])
print(result["recommendations"][:1])
Using as a LangChain tool:
tool = wf.as_tools()[0]
output = tool.invoke({"intent_description": "Write a business proposal"})
print(output["recommendations"])
Caveats
- The workflow prints progress logs directly to stdout.
queries_file_pathmust exist; otherwiseFileNotFoundErroris raised during initialization.- Intent matching is keyword-based and selects among fixed query IDs:
abi#findBusinessProposalAgents(default fallback)abi#findCodingAgentsabi#findMathAgentsabi#findFastestAgentsabi#findBestValueAgentsMissing IDs in the loaded TTL will causeKeyErrorat runtime when selected.
- Template substitution is simple string replacement for
{{ key }}plus a basic{% if var %}...{% endif %}processor; more complex templating is not supported. max_input_costandprovider_preferenceare only applied if the SPARQL template includes corresponding placeholders/conditionals; otherwise they have no effect.