← Back to Technical blog

Technical article

Which External Systems Can an Agent Use? Tool Contracts, Validation, and Fallbacks

Data Agent can integrate at several levels, including data ingestion, analytics sessions, and business execution.

Dec 3, 2026Technical blogHENGSHI20 min read

Article body

Full article

0 Summary

Data Agent can integrate at several levels, including data ingestion, analytics sessions, and business execution. Using HENGSHI SENSE 7.0, this article distinguishes third-party metric ingestion, in-application tool calls, and external actions performed by a host system. It describes parameter validation, traceability, recovery, and how to confirm write outcomes.

1 Tools connect agents to external systems

1.1 What tools do

Data Agent in HENGSHI SENSE 7.0 runs on the server. Q&A uses existing data and metrics to produce findings and charts. Operation creates or changes BI resources within the user’s permissions. A business system can call the Data Agent session interface or bring external data into the platform through controlled ingestion. CRM writebacks, IM messages, and publishing to external systems use the integration and authorization processes of those systems.

1.2 The tool layer isolates the model from the back end

The model selects a tool and supplies parameters. The tool layer handles connections, dialects, and permissions. Back-end changes need not force the model to relearn the system, and the model only receives the access exposed by the tool. This boundary helps maintain security and stability.

1.3 A short tool list makes selection easier

A long list makes it easy for a model to select the wrong tool and may contain overlapping tools. Group tools by action and keep a set whose meanings and boundaries are clear. Before adding a tool, explain which action the existing tools cannot cover.

1.4 Tools and business skills have different roles

Tools carry out specific controlled actions. Runtime skills can supply industry terms, business definitions, and instructions for using existing tools. SENSE 7.0 administrators can upload and enable skills and verify them with representative Q&A and Operation requests. Browser-defined custom tools are no longer part of the Data Agent execution path in that release. The delivery scope in the 7.0 documentation also excludes MCP service integration.

2 The tool inventory and its granularity

2.1 Divide tools by action

Each tool should represent an independently verifiable action, such as querying data or drawing a chart. Bundling actions into one tool complicates inputs and outputs and makes it harder for the model to identify where a failure occurred. Match tool granularity to the task steps.

2.2 Separate read and write operations

Manage query and read tools separately from tools that edit, publish, or send data. Writes require stricter confirmation and auditing and should have their own call workflow. This lets each category apply the relevant permission checks and risk notices.

2.3 Write descriptions the model can understand

Give each tool a clear name, purpose, explanation of parameters, and response format. Vague descriptions lead to wrong choices or wrong inputs. Treat tool descriptions as maintained assets and update them with the underlying interface.

2.4 Review the tool list regularly

Check for duplicate tools, whether each tool is still used, and whether its description agrees with the back end. Consider retiring unused tools and consolidating tools with similar purposes. Review tools on the same cadence as metric definition assets to prevent uncontrolled growth.

Review granularity as well. Tools that cover too much need complex parameters. Tools that are too fine-grained produce a sprawling inventory. Check each tool against an action that can be verified on its own.

Table 1. Common types of tool integration and their roles

Integration needAvailable interfaceWhat to verify
Query internal analytics assetsSENSE Data Agent Q&ACheck the metric definition, scope, and source of results under the current user’s permissions
Ingest third-party metricsMetric API data source and the corresponding subject areaVerify third-party authentication, metric dimensions and units, and update time
Present analytics in a host applicationiframe, browser SDK, or HTTP APIVerify login, data scope, streaming results, and recovery
Create resources in BISENSE Data Agent OperationConfirm the target resource and existing permissions and check the actual change receipt
Carry out external actions such as CRM or IMThe host’s own service interface or workflowSpecify the approver, scope, idempotency, and target system receipt

3 Interface contracts: Inputs, outputs, and types

3.1 Type each input explicitly

Give every tool parameter a type. For a time range, organization code, metric identifier, or dimension name, say what format it uses, whether it is required, and what values it accepts. If types are unclear, the model has to guess and errors accumulate at the parameter layer.

3.2 Use a stable output structure

Return a stable structure with data fields, row count, information on the metric definition, and a status. Downstream steps can parse a consistent contract. Free text and variable formats force the interpretation layer to keep adapting.

3.3 Return errors through the same contract

On failure, return a structured error with the type, reason, and whether a retry is allowed. The calling layer can then handle each case: correct invalid parameters, stop retrying permission failures, and use a fallback for timeouts.

3.4 Define defaults and constrain enumerations

Set explicit defaults for optional parameters and use enumerations for allowed values where possible. Enums allow prevalidation to catch wrong inputs. Free text requires additional validation and correction. Document defaults in the tool description so the model knows when a parameter can be omitted.

Maintain compatibility when enums change. Introduce new values gradually, allow a transition period for deprecated values, and record which version a call used. A stable interface saves the calling workflow from adapting repeatedly to back-end changes.

3.5 Specify timeouts and rate limits

Set a timeout and rate limits for each tool, including how long to wait for a slow service and how many requests can be concurrent. Return a structured error on timeout so the task does not wait indefinitely. Match rate limits to the external service’s capacity to avoid passing on excess concurrency.

Monitor timeouts and rate limiting. Identify the tool types that time out most and the times when failures cluster. Use these observations to adjust thresholds and fallback strategies so individual timeouts need not become user-visible failures.

4 Validate parameters and permissions before calling

4.1 Check parameters before sending the request

Check that required inputs are present, values are valid, and requested scope fits the user’s permissions. Return invalid input to the model for correction without sending an external request. Prevalidation filters invalid calls and reduces load on the back end.

4.2 Tool calls inherit the user’s identity

SENSE Data Agent uses server-side authentication to identify the user and tenant and checks resource permissions. The embedded host supplies data scope and page context to locate resources. The platform checks actual access for the current user. Controlled connections and upstream services manage authentication to third-party data sources.

4.3 Confirm only actions that the platform exposes and requires the user to confirm

To create an execution plan, for example, show the proposal first. An authorized user confirms it, and the platform rechecks the resource and when the plan expires. Application publishing, sharing, granting access, and data export still use their respective product interfaces.

4.4 The host business system performs external writes

If the host needs to write user-reviewed findings into a CRM, follow the CRM’s authorization and approval rules. The host records the target object, idempotency key, status, and receipt. After a timeout, first check the target system for a completed write.

5 Verify tool results

5.1 Check magnitude and completeness

When the tool returns, check for empty results, a plausible row count, and values in the expected range. An empty result can come from the filters or from data that has yet to arrive. Distinguish those cases before treating it as an answer.

5.2 Match the definition and context

Check that the result uses the definition and scope agreed for the task. An external service might use a different definition. Include the source definition in the response and reconcile it with task context before advancing.

5.3 Keep results traceable

Record the tool name, inputs, returned row count, duration, and source for each call. Those records help investigation and form part of the answer’s provenance. Without a call record, the conclusion is hard to explain or reproduce.

5.4 Check consistency across tools

Compare outputs of tools within the same task. Do query and display results agree? Does the aggregate reconcile to the detail? Mismatches often indicate a definition or parameter problem. Find them before delivery.

Useful checks include comparing aggregate values with detail totals, row counts with source records, and key metrics with historical magnitudes. Simple rules can catch obvious misalignments.

Table 2. Tool failure types and responses

SituationWhat to check firstResponse
Missing parameterInterface contract and agreed business scopeSupply the parameter or ask the user for clarification
401 or 403Current identity, target resource, and corresponding access rightsResolve authentication or authorization before proceeding
SSE disconnectWhether the run identifier arrived and what state the server reportsQuery by runId and read back the persisted turn
Unknown outcomeWhether the business system already has the object or an execution receiptReconcile first and retry only after confirming it did not execute
Incomplete dataQuery time, fields, row count, and definitionIdentify what is missing and the scope affected

6 Fallbacks and alternative paths

6.1 Distinguish retryable and non-retryable failures

Retry read-only, idempotent queries within the system’s limits. Handle access denial, disagreements over definitions, and unknown outcomes of external writes separately. After a conversation turn POST times out, query the original run state before sending another request. A network error alone gives no basis for a retry.

6.2 Use alternatives when available

If the primary tool is unavailable, consider another data source or a different query method. Preserve the metric definition across both execution paths. If there is no alternative, deliver a partial result and explain the gap.

6.3 Keep authorization in force during fallback

A fallback must stay within access controls. When switching tools or sources, recheck the accessible scope for the current user. Do not carry over a scope that was dropped by the primary tool.

6.4 Record the fallback

Log each retry, tool change, and reduction in scope, including the failure cause, alternative used, and final outcome. These records show which tools are unreliable and which tasks fail, informing tool design. Without them, failures may only be visible to the user.

For a partial delivery, record the data scope covered and what remains missing. Use the destination system’s actual receipt to confirm existing business outcomes.

6.5 In practice: Check state after a streaming connection drops

The SENSE 7.0 data client SDK provides session and run queries. On chat.created, bind the actual conversationId, runId, and chatUid to the UI message. If the connection drops, query the run before reading the turn once the client has confirmed a terminal state. This avoids submitting the same turn again.

async function readRun(agent, conversationId, runId) {
  return agent.getRun({ conversationId, runId });
}

async function readSavedChat(agent, conversationId, chatUid) {
  return agent.getChat(conversationId, chatUid);
}

The host calls readRun first and keeps checking while the run is active. After it ends, the host calls readSavedChat. SSE updates support live display. An end event alone cannot establish that analysis or a write succeeded. If identifiers are unavailable, record request correlation information and inspect history. Keep success, failure, and unknown outcome distinct for external writes.

Engineering teams with existing automation can use HENGSHI CLI for BI actions within their authorization. Use a dry run where supported and verify the result. The CLI serves engineering execution, while the session SDK serves conversational integration. Confirm results through the interface actually used.

7 Tool versions and maintenance

7.1 Preserve compatibility as interfaces change

Adapt external interface upgrades in the tool layer to shield the model from the changes. Keep inputs and outputs backward-compatible, phase out deprecated fields gradually, and distinguish old and new versions in call records.

7.2 Make tool health observable

Measure call volume, success rate, duration, and timeout rate for each tool. Detect persistent failures and disable or fix the affected tool before users have to report wrong answers.

7.3 Maintain tools alongside semantic assets

Metrics and fields a tool uses change with the semantic layer version. When a definition changes, update the relevant tool descriptions and validation rules so tools do not continue using the old definition.

7.4 Retire tools through a planned process

Before removing a tool, check whether any task or skill still depends on it. Mark it deprecated, provide a transition period, and then retire it. Record dependencies so retirement does not interrupt active work.

Record when a tool changed or was retired, who used it, and why it was replaced. That supports troubleshooting and inventory reviews and keeps obsolete tools from returning unnoticed.

7.5 Track tool health metrics

Track call count, success rate, average duration, timeout share, and failure types over time. If a metric deteriorates, distinguish back-end instability from a contract problem before deciding how to fix it. Review health alongside business usage to see whether the tool remains valuable.

8 Antipatterns

8.1 Letting models construct direct back-end calls

When a model bypasses the tool layer to access back-end systems, parameter and permission checks are lost. Security and stability can no longer be assured. Route actions on external systems through controlled tools.

8.2 Making one tool do many things

A tool that combines queries, chart creation, and delivery needs complex inputs and makes failures difficult to locate. Separate action types to clarify boundaries and make tools easier to troubleshoot and reuse.

8.3 Logging failures without handling them

If an exception only goes into a log, the user may just see “No results.” Classify failures and provide a next step. Logs support troubleshooting alongside feedback to users.

8.4 Expanding tool responsibilities with every new request

Adding parameters and branches for each new requirement turns a tool into a broad interface with unclear boundaries. Decide whether a new action calls for its own tool or a business skill. Keep the general-purpose interface focused.

9 Boundaries and conclusion

A mature tool layer depends on well-defined external interfaces. Arbitrary back-end changes and unstable contracts increase adaptation costs. Write tools have another boundary. Until the workflow has been confirmed, keep their availability to a minimum and start with read-only analysis.

Judge usability against engineering checks. Look for stable contracts, validation before calls, results that can be checked, failure handling with appropriate fallback, and observable changes. Together these make connections to external systems controlled integrations.

Start external business system integration with read-only analysis. Before adding cross-system writes, verify explicit approval, resource-level permissions, and idempotent execution. Confirm the outcome by reading a receipt in the external system.

For each new class of tool, check its contract, validation, fallback, and observability before adding it to the approved inventory.

The tool layer gives the model and back-end systems a defined contract. A clear inventory, typed inputs and outputs, permission checks before calls, definition checks on results, categorized fallbacks, and maintainable versions keep external integrations controlled.

About HENGSHI Technology

Founded in 2016, HENGSHI Technology pioneered the definition of a new generation of Agentic BI for the Data + AI era. Its enterprise analytics platform, HENGSHI SENSE, works with HENGSHI Super Digital Employee, the HENGSHI CLI execution engine, and HENGSHI BOX, its privately deployed operations and control hub, to form an integrated suite of services. With a decade of experience in BI analytics, HENGSHI continues to support software vendors across industries through its Powered by Hengshi ecosystem strategy. It provides integrated, end-to-end AI analytics in trusted private environments for business operations and data-driven decision-making at enterprise groups in manufacturing, finance, retail, government, and other sectors.

HENGSHI SENSE

Resources, ecosystem, and implementation stories

Explore how teams design and ship analytics with HENGSHI.

Request a trial

Enterprise deployment, embedded delivery, and trial requests can all be handled quickly.