Factory that constructs and returns an EntitytoSPARQLAgent using the default model (naas_abi.models.default.get_model()), MemorySaver checkpointer, and provided (or new) shared state/configuration.
from langchain_core.messages import AIMessagefrom naas_abi.agents.EntitytoSPARQLAgent import create_agentagent = create_agent()# Build the internal graph (required before running, depending on Agent base implementation)agent.build_graph()# Provide input text as a message in the agent state and run the compiled graphinitial_state = {"messages": [AIMessage(content="Alice signed a contract with Bob yesterday.")]}# If the base Agent exposes a LangGraph app, it's typically something like:result = agent.graph.invoke(initial_state)# The final SPARQL is stored in the last message contentprint(result["messages"][-1].content)
Caveats
entity_extract expects the model to return only JSON (per prompt). prep_data will fail if JSON cannot be extracted from the last message.
prep_data assumes state["messages"][-2] exists (used to save init_text.txt); the graph order must ensure there is an original message before the extraction response.
SPARQL generation is model-driven; correctness depends on model compliance with the prompt constraints.
Default constructor arguments use mutable defaults (tools=[], agents=[]), which may cause shared state across instances if those lists are mutated.