Class AgentConnectorImpl
- All Implemented Interfaces:
AgentConnector,Connector<AgentRequest>
Execution flow per invocation:
- Instantiate any tool objects listed in
toolClasses(fail fast before network I/O). - Resolve the base URL from the request parameter, the
OPENAI_BASE_URLenvironment variable, orAgentConnectorConstants.DEFAULT_BASE_URL. - Resolve the API key from the request parameter or, for the configured
endpoint only, the
OPENAI_API_KEYenvironment variable. - Build an
OpenAiChatModelfrom the request parameters. - Create a stateless
AiServicesproxy and invoke it with the user message. - Return an
AgentResponsecontaining the output text and a correlation UUID.
Within an agentic ad hoc scope's turn, the model loop keeps a hallucinated tool name, a tool failure, and a tool refusal in bounds rather than failing the step:
- A tool name outside the scope's catalogue is corrected in chat memory and costs the
turn's model-call cap exactly the one call that made it up — see
hallucinatedToolMessage(dev.langchain4j.agent.tool.ToolExecutionRequest, org.cibseven.connect.ai.agent.impl.AgentConnectorImpl.AvailableTools)andresolveHallucinatedTool(org.cibseven.connect.ai.agent.AgentRequest, java.lang.String, java.lang.String, org.cibseven.connect.ai.agent.impl.AgentConnectorImpl.AvailableTools)(CIB7-2150). - An engine failure ends the step rather than reaching the model in a transaction that
can no longer commit — see
toolFailure(java.lang.Throwable, dev.langchain4j.service.tool.ToolErrorContext)(CIB7-2141). - A refusal (wrong arguments, a blocked activity) is an answer the model reads and may
act on in its next call — see
immediate(dev.langchain4j.service.tool.ToolProvider)andAgentConnectorImpl.FailureAsResult.
-
Field Summary
Fields inherited from class org.cibseven.connect.impl.AbstractConnector
connectorId, requestInterceptorsFields inherited from interface org.cibseven.connect.ai.agent.AgentConnector
ID, PARAM_NAME_AGENT_DESCRIPTION, PARAM_NAME_AGENT_NAME, PARAM_NAME_API_KEY, PARAM_NAME_BASE_URL, PARAM_NAME_CHAT_MEMORY_MAX_MESSAGES, PARAM_NAME_CONTEXT_VARIABLES, PARAM_NAME_CUSTOM_HEADERS, PARAM_NAME_DOCUMENT_DETAIL_LEVEL, PARAM_NAME_DOCUMENT_MIME_TYPES, PARAM_NAME_DOCUMENTS, PARAM_NAME_EMBEDDING_DIMENSION, PARAM_NAME_EMBEDDING_MODEL_NAME, PARAM_NAME_INSTRUCTION, PARAM_NAME_INSTRUCTION_MODE, PARAM_NAME_MAX_RAG_RESULTS, PARAM_NAME_MCP_SERVERS, PARAM_NAME_MEMORY_ID, PARAM_NAME_MESSAGE, PARAM_NAME_MIN_RAG_SCORE, PARAM_NAME_MODEL, PARAM_NAME_OPTIONAL_CONTEXT_VARIABLES, PARAM_NAME_OUTPUT, PARAM_NAME_OUTPUT_AI_META, PARAM_NAME_PERSIST_CHAT_LOG, PARAM_NAME_PG_DATABASE, PARAM_NAME_PG_HOST, PARAM_NAME_PG_PASSWORD, PARAM_NAME_PG_PORT, PARAM_NAME_PG_TABLE, PARAM_NAME_PG_USER, PARAM_NAME_REASONING_EFFORT, PARAM_NAME_REASONING_SUMMARY, PARAM_NAME_TOOL_CLASSES, PARAM_NAME_USE_CHAT_MEMORY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected dev.langchain4j.mcp.client.McpClientbuildMcpClient(String url, Map<String, String> headers) Factory method for a single MCP client — override in tests to capture arguments and avoid opening a real transport connection.protected dev.langchain4j.memory.chat.ChatMemoryProvidercreateChatMemoryProvider(AgentRequest request) Factory method — builds theChatMemoryProviderused when chat memory is active.protected dev.langchain4j.model.chat.ChatModelcreateChatModel(AgentRequest request, String apiKey, String baseUrl, Map<String, String> customHeaders) Factory method — override in tests to inject a stubbed chat model.protected dev.langchain4j.rag.content.retriever.ContentRetrievercreateContentRetriever(AgentRequest request) Factory method — builds and returns aContentRetrieverbacked by pgvector whenpgHostis present in the request, ornullto skip RAG entirely.protected dev.langchain4j.model.embedding.EmbeddingModelcreateEmbeddingModel(AgentRequest request) Factory method — override in tests to inject a stubbed embedding model.protected List<dev.langchain4j.mcp.client.McpClient>createMcpClients(AgentRequest request) Factory method — override in tests to inject stubbed MCP clients.protected dev.langchain4j.store.embedding.EmbeddingStore<dev.langchain4j.data.segment.TextSegment>createRagEmbeddingStore(AgentRequest request) Factory method — builds the pgvector embedding store used as the RAG backend.Create a request on the connector.execute(AgentRequest request) Execute the request on the connector.Methods inherited from class org.cibseven.connect.impl.AbstractConnector
addRequestInterceptor, addRequestInterceptors, getId, getRequestInterceptors, setRequestInterceptorsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.cibseven.connect.spi.Connector
addRequestInterceptor, addRequestInterceptors, getId, getRequestInterceptors, setRequestInterceptors
-
Constructor Details
-
AgentConnectorImpl
public AgentConnectorImpl()
-
-
Method Details
-
createRequest
Description copied from interface:ConnectorCreate a request on the connector.- Specified by:
createRequestin interfaceConnector<AgentRequest>- Returns:
- the connector-specific request object.
-
execute
Description copied from interface:ConnectorExecute the request on the connector.- Specified by:
executein interfaceConnector<AgentRequest>- Parameters:
request- the request- Returns:
- the result.
-
createChatMemoryProvider
protected dev.langchain4j.memory.chat.ChatMemoryProvider createChatMemoryProvider(AgentRequest request) Factory method — builds theChatMemoryProviderused when chat memory is active. Each provider call returns aMessageWindowChatMemorybound to whatever storeAgentChatMemoryStorecurrently holds, so how long the conversation survives depends on that store rather than on this factory.With the default
ProcessVariableChatMemoryStoreit survives between connector invocations, across engine restarts and across engine replicas. It does not when the deployment has switched the store to the JVM-local one, when a custom store was installed viaAgentChatMemoryStore.setStore(dev.langchain4j.store.memory.chat.ChatMemoryStore), or when the connector runs outside an engine command context — the process-variable store then falls back to an in-memory buffer. -
createMcpClients
Factory method — override in tests to inject stubbed MCP clients.Builds one client per entry of the
mcpServersJSON array. Returns an empty list whenmcpServersis not configured. -
buildMcpClient
protected dev.langchain4j.mcp.client.McpClient buildMcpClient(String url, Map<String, String> headers) Factory method for a single MCP client — override in tests to capture arguments and avoid opening a real transport connection. -
createContentRetriever
protected dev.langchain4j.rag.content.retriever.ContentRetriever createContentRetriever(AgentRequest request) Factory method — builds and returns aContentRetrieverbacked by pgvector whenpgHostis present in the request, ornullto skip RAG entirely. Override in tests to inject a stubbed retriever.The returned
ContentRetrieverwraps the underlyingEmbeddingStoreContentRetrieverto (a) keep the existing SLF4J logging and (b) emit atype: "retrieval"event into theAgentChatListeneractive on the calling thread (viaProcessStarterToolContext.getActiveListener()). The retrieval event carries the query, embedding-model identity, the pgvector store coordinates (host/port/database/table/dimension — never the password), the retrieval parameters (maxResults,minScore), and per-chunk{score, content, length, metadata}entries. Query and chunk text are run throughAgentChatListener.maybeRedact(String)so they honour the sameredactContentopt-in that chat events already respect. On failure the event carrieserrorClass,message, and a short stack identical in shape toonError— see EU AI Act Art. 10 (data governance) / Art. 12 (record-keeping) / Art. 26 (deployer monitoring). -
createRagEmbeddingStore
protected dev.langchain4j.store.embedding.EmbeddingStore<dev.langchain4j.data.segment.TextSegment> createRagEmbeddingStore(AgentRequest request) Factory method — builds the pgvector embedding store used as the RAG backend. Override in tests to inject a stubbed store and avoid opening a real database connection. -
createEmbeddingModel
Factory method — override in tests to inject a stubbed embedding model. UsesOpenAiEmbeddingModelatAgentConnectorConstants.DEFAULT_BASE_URLwhenembeddingModelNameis set on the request (the request'sbaseUrlis not used), otherwise falls back to the localAllMiniLmL6V2EmbeddingModel. The key comes fromresolveAgentEmbeddingApiKey(org.cibseven.connect.ai.agent.AgentRequest). -
createChatModel
protected dev.langchain4j.model.chat.ChatModel createChatModel(AgentRequest request, String apiKey, String baseUrl, Map<String, String> customHeaders) Factory method — override in tests to inject a stubbed chat model.Selects the OpenAI Responses API (
OpenAiResponsesChatModel) whenreasoningSummaryis set on the request — that field is only available on the Responses API. Otherwise builds the standardOpenAiChatModel.reasoningEffort, when present, is forwarded to whichever builder is used.
-