---
title: "Function: createAgent()"
editUrl: true
head: []
template: doc
sidebar:
  hidden: false
  attrs: {}
pagefind: true
draft: false
---

[**Prefactor TypeScript SDK**](../../../index.md)

***

[Prefactor TypeScript SDK](../../../modules.md) / [@prefactor/openclaw-prefactor-plugin](../index.md) / createAgent

# Function: createAgent()

> **createAgent**(`config`, `logger`): [`Agent`](../interfaces/Agent.md)

Defined in: [packages/openclaw-prefactor-plugin/src/agent.ts:873](https://github.com/prefactordev/typescript-sdk/blob/231423a775642bec119a2db45acf108c6383d05d/packages/openclaw-prefactor-plugin/src/agent.ts#L873)

Creates and returns a fully initialised [Agent](../interfaces/Agent.md) instance.

On construction the Agent starts a background flush loop (every 30 s) that
retries any previously failed network operations. No immediate network calls
are made; the first API request occurs when a span is created or an
AgentInstance is registered for a session.

## Parameters

### config

[`AgentConfig`](../interfaces/AgentConfig.md)

[AgentConfig](../interfaces/AgentConfig.md) with API URL, token, agent ID, and optional retry/timeout settings.

### logger

[`Logger`](../interfaces/Logger.md)

Logger instance for structured diagnostic output.

## Returns

[`Agent`](../interfaces/Agent.md)

A new [Agent](../interfaces/Agent.md) ready to manage sessions and spans.