Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 10 min read

Reusing Agents as Sub-Agents: Building an Internal Library That Compounds in Value

In one sentence: An internal library of well-specified, owned and versioned sub-agents lets every new workflow start from proven building blocks, so each improvement spreads to every consumer instead of being rebuilt and

Reusing Agents as Sub-Agents: Building an Internal Library That Compounds in Value

In one sentence: An internal library of well-specified, owned and versioned sub-agents lets every new workflow start from proven building blocks, so each improvement spreads to every consumer instead of being rebuilt and fixed, again and again.

The first few agents in an organization are usually built from scratch, by whoever had the idea and the time. That is fine, until the third team builds the same document checker as the first two and slightly differently. Agent sprawl is a quiet cost: duplicated effort, inconsistent behavior and fixes that must be made in several places. This post explains how to turn specialist agents into reusable sub-agents and how to run an internal library so that its value compounds. We use the STAR format (Situation, Task, Action, Result) to move from sprawl to a library people trust.

Three Teams, Three Document Checkers

Consider a diversified financial group we’ll call Cedar Financial Group. As in our earlier posts, this is a composite scenario, not a customer case, but the pattern is a common one.

Cedar has three business units: lending, insurance and wealth management. Each decides, independently and sensibly, to use AI agents to speed up customer onboarding. Each builds an agent that checks identity documents. The lending team’s version is thorough but slow. The insurance team’s is fast but ignores one document type. The wealth team’s was copied from a conference demo and adapted and nobody is quite sure how it handles expired passports.

For a while, this does no harm. Then a regulator changes the guidance on acceptable identity documents. Compliance sends a notice and three teams must update three agents. Two do so within a week. The third is mid-reorganization and the change is delayed. For several weeks, one unit’s agent accepts a document that the other two correctly reject. A customer who is declined by one unit and accepted by another asks a question nobody can answer comfortably: why do you treat the same document differently?
The problem repeats elsewhere. Each unit has its own address-normalization logic, its own summarizer for customer correspondence and its own approach to redacting personal data. Improvements made in one place never reach the others. New teams do not know what already exists, so they build again.

The organization has plenty of agents and little accumulated capability.
This is the situation that software engineering solved long ago with shared libraries and internal platforms. The lesson transfers directly to agents, with some adjustments for the way agents behave. Figure 1 contrasts duplicated and reused agents.

Figure 1. Copied agents vs. a shared library

The consequences go beyond efficiency. Inconsistent agents create compliance exposure, because the same rule is applied three ways. They create customer-facing inconsistency. And they waste the most valuable thing a young agent program has: lessons learned. When each team learns privately, the organization learns slowly.

Sprawl also has a human cost. Talented people spend their time rebuilding what a colleague two floors away has already built and then spend more time maintaining it. New joiners cannot tell which of several similar agents is the trusted one. Over time, teams learn to distrust anything built outside their own unit, which makes sharing even rarer and the sprawl even worse.

Pause and check: List the capabilities your agents share, such as document checking, summarizing, redacting or looking up customers. How many separate implementations of each exist today and who owns each one?

Build a Library People Want to Use

Your task is to create an internal library of sub-agents that teams actually adopt. Reuse does not happen by announcement; it happens when borrowing is easier and safer than rebuilding. That requires six qualities in every reusable sub-agent.

  1. A single, clear job. It does one thing well, stated in one sentence.
  2. A stable contract. Defined inputs and outputs that consumers can rely on.
  3. Versions. Changes are released deliberately, with a record of what changed.
  4. An owner. A named person or team is accountable for quality and support.
  5. Tests and known limits. Consumers can see how it was tested and where it falls short.
  6. Discoverability. Teams can find it, understand it and try it quickly.

A caution belongs here. Reuse can be pursued too eagerly. Extracting a component before it is understood produces a library of awkward, over-general parts that nobody wants. A sensible rule of thumb is to extract a capability when you see it needed a third time, because by then you know what varies and what stays the same.

For Cedar, the task becomes concrete: replace three document checkers with one owned, versioned sub-agent, publish it in a catalog with a clear contract and set up a way to change it safely without breaking its consumers.

Running the Library

Figure 2 shows the intended shape: a small catalog of sub-agents, each used by several workflows.

Figure 2. An internal agent library and its consumers
CONSUMER WORKFLOWS AGENT LIBRARY (catalog)

Loan onboarding ----+-----> document-check v2.3.1
Insurance claims ----+-----> sanctions-screening v1.4.0
Wealth onboarding ----+-----> address-normalizer v3.0.2
Vendor onboarding ----+-----> pii-redaction v1.2.5
+-----> correspondence-summary v1.0.3

Each entry: one job, a contract, a version, an owner, tests, limits.

What a library entry contains

Every sub-agent in the library is described by the same set of facts. Figure 3 lists them. Think of this as the packaging that makes a capability safe to borrow.

Figure 3. Anatomy of a library entry

The consumers field is easy to overlook and extremely valuable. It tells the owner who will be affected by a change and it tells prospective users who else has already trusted this component.

Versioning that protects consumers

A shared component changes over time and its consumers need to know what a change means for them. Borrowing the convention from software, label versions as major, minor and patch. A patch fixes a defect without changing the contract. A minor release adds an optional capability. A major release changes the contract or materially changes behavior. Consumers pin to a major version, so that patches and minor releases flow in automatically after tests pass, while a major change requires a deliberate migration.

Figure 4 summarizes what each kind of change should trigger.

The library in code

Now the technical part. The snippets below are simplified, illustrative Python rather than a production framework. The first is a catalog entry, a plain, immutable description of a sub-agent that can be reviewed and searched.

Figure 5a. A catalog entry
`from dataclasses import dataclass

@dataclass(frozen=True)
class LibraryEntry:
name: str
version: str # MAJOR.MINOR.PATCH
owner: str
purpose: str # one sentence, one job
input_schema: dict
output_schema: dict
allowed_tools: tuple
known_limits: tuple
status: str = "active" # active | deprecated | retired`

The second snippet shows how a consumer pins to a major version and receives the newest compatible release. If no compatible version exists, the consumer is told plainly that a migration is needed.

Figure 5b. Pinning to a major version
`PINS = {"document-check": 2, "sanctions-screening": 1} # major versions

def resolve(available: list, major: int) -> str:
same_major = [v for v in available if int(v.split(".")[0]) == major]
if not same_major:
raise LookupError(f"No release with major {major}: migration needed")
return max(same_major, key=lambda v: tuple(map(int, v.split("."))))

resolve(["2.3.0", "2.3.1", "3.0.0"], 2) -> "2.3.1"`

The third snippet is the safeguard that makes sharing safe. Before a new release goes out, the library runs it against test cases contributed by each consumer. If any consumer’s cases fail, the release is blocked and the owner knows exactly whom it would have broken.

Figure 5c. A release gate driven by consumer tests
def release_gate(candidate, consumer_suites: dict):
failures = {}
for consumer, cases in consumer_suites.items():
broken = [case["id"] for case in cases
if not passes(candidate.run(case["input"]), case["expect"])]
if broken:
failures[consumer] = broken
return (not failures), failures # blocks the release and names who would break

Three ideas sit behind these snippets. The contract is explicit, so consumers know what they are getting. Versions carry meaning, so upgrades are predictable. And consumers contribute tests, which turns the library’s quality into a shared responsibility. A sub-agent that has been tested against four consumers’ real cases is more trustworthy than one tested only by its author.

Not everything belongs in the library. Some agents are genuinely specific to one workflow and forcing them into a shared form only adds ceremony. A useful test is to ask whether a second team could use the component without changing it. If the honest answer is no, keep it local. If the answer is β€œyes, with small changes,” consider adding an optional parameter before creating a fork, because forks are how drift begins again.

Making it adoptable

A technically sound library can still fail if nobody uses it. Adoption depends on a few human factors. Make the catalog easy to browse, with a plain-language description and a short example for each entry. Give owners a service commitment, such as how quickly defects are triaged. Offer a quick way to try a sub-agent on sample data before committing. And invite contributions: when a team builds something others could use, provide a path to promote it into the library, with a review that checks the contract, the tests and the permissions.

Governance should be light but real. Each sub-agent is reviewed once, for security, data handling and fit and every consumer then benefits from that review. This is one of the quiet advantages of a library: the effort of getting approval is spent once and reused many times, instead of being repeated for every copy.

What Good Looks Like

As in our previous posts, we will not promise a specific saving or speed-up. Results depend on your portfolio, your teams and how much overlap actually exists, so measure the duplication you have today and add verified figures before presenting a business case.

What does change is the shape of the organization’s capability. For Cedar, the next regulatory change is a single update to one document-check sub-agent, released as a patch after the consumers’ tests pass. All four workflows receive it together and no customer is accepted by one unit and declined by another for the same document. A new team building a vendor onboarding workflow starts by browsing the catalog and finds that three of the five capabilities it needs already exist. Its effort goes to the part that is genuinely new.

This is what it means for value to compound. Each sub-agent that enters the library makes the next workflow cheaper to build. Each improvement benefits every consumer. Each consumer’s test cases make the component more robust. Over time, the library becomes a store of the organization’s hard-won knowledge about how to do things well and new agents inherit it by default.

Expect the first months to include some friction. Teams will disagree about contracts, owners will feel the weight of supporting others and the first major release will require careful migration. These are the normal costs of shared infrastructure and they are far smaller than the costs of repeated divergence. The key is to keep the library small, useful and trusted and to grow it only as fast as real demand justifies.

Figure 6. A scorecard for an internal agent library

Three pitfalls to avoid
β€’ Extracting too early. A component generalized before it is understood becomes awkward for everyone. Wait until a capability has been needed a third time.
β€’ A library with no owners. Unowned entries decay. Every sub-agent needs a named owner and a service commitment.
β€’ Unpinned consumers. If workflows always take the latest version, any release can break them. Pin to a major version and upgrade deliberately.
Figure 7. STAR recap

Where should you start?

List the capabilities that more than one of your agents performs. Choose the one that appears most often and matters most, perhaps document checking or data redaction. Define its contract in one page, name an owner, collect two or three test cases from each current user and publish it in a simple catalog, even if that catalog is a shared document at first. Move one consumer onto it, then the next. The library does not have to be large to start paying back; it has to be trusted.

An organization’s agents are only as valuable as its ability to build on what it already has. Treat sub-agents as products with owners, contracts and versions and each new workflow stands on the shoulders of the last. That is the difference between a collection of agents and a capability that grows.

Ready to go deeper? Explore how agents are built on the IntelliBooks.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.