Variable: AgentContext

typescript
1
const AgentContext: Context<undefined | { agent: null | Agent; setAgent: (agent) => void; start: () => Promise<void>; state: State; stop: () => Promise<void>; }>

Defined in: packages/identus-react/src/context/index.ts:316

React context for managing the main Identus Agent operations.

The Agent is the central orchestrator for all Identus SDK operations including DIDComm messaging, credential operations, and connection management. This context provides access to agent lifecycle management and core functionality.

Example

tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { AgentContext } from '@trust0/identus-react/context';
import { useContext } from 'react';
function AgentManager() {
const context = useContext(AgentContext);
if (!context) {
throw new Error('AgentManager must be used within AgentProvider');
}
const { agent, start, stop, state, setAgent } = context;
const handleStart = async () => {
try {
await start();
console.log('Agent started successfully');
} catch (error) {
console.error('Failed to start agent:', error);
}
};
return (
<div>
<p>Agent State: {state}</p>
<button onClick={handleStart} disabled={state === 'running'}>
Start Agent
</button>
<button onClick={stop} disabled={state !== 'running'}>
Stop Agent
</button>
</div>
);
}