Agent¶
PhyTraceAgent¶
PhyTraceAgent ¶
PhyTraceAgent(config: AgentConfig | None = None, transport: Transport | None = None)
PhyTrace Agent - orchestrates telemetry collection and transmission.
The agent provides: - License validation before operation - Event validation before sending - Provenance tagging for trust - Batching for efficiency - Local buffering for offline operation - Retry logic with circuit breaker - Multiple transport options
Example
From configuration file¶
agent = PhyTraceAgent.from_config("phytrace-agent.yaml") await agent.start()
event = UDMEventBuilder(...).build() await agent.emit(event)
await agent.stop()
With mock transport for testing¶
agent = PhyTraceAgent(transport=MockTransport()) await agent.emit(event)
Initialize the PhyTrace Agent.
| PARAMETER | DESCRIPTION |
|---|---|
config | Agent configuration (uses defaults if not provided) TYPE: |
transport | Transport implementation (created from config if not provided) TYPE: |
Source code in phytrace/agent.py
Attributes¶
transport property ¶
transport: Transport | None
Get the transport (useful for testing with MockTransport).
Methods:¶
from_config classmethod ¶
from_config(config_path: str | Path) -> PhyTraceAgent
Create an agent from a YAML configuration file.
| PARAMETER | DESCRIPTION |
|---|---|
config_path | Path to configuration file TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
PhyTraceAgent | Configured PhyTraceAgent instance |
Source code in phytrace/agent.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
start async ¶
Start the agent and establish connections.
Source code in phytrace/agent.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | |
heartbeat_event ¶
heartbeat_event() -> UDMEvent
A system.heartbeat event stating the heartbeat interval in its PhyUDM heartbeat block.
Source code in phytrace/agent.py
stop async ¶
Stop the agent and flush remaining events.
Source code in phytrace/agent.py
emit async ¶
emit(event: UDMEvent) -> SendResult
Emit a single event.
The event is validated, tagged with provenance and license metadata, and sent through the configured transport. If batching is enabled, the event may be held until the batch is full.
| PARAMETER | DESCRIPTION |
|---|---|
event | The UDM event to send TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
SendResult | SendResult indicating success or failure |
Source code in phytrace/agent.py
emit_batch async ¶
emit_batch(events: list[UDMEvent]) -> BatchSendResult
Emit a batch of events.
| PARAMETER | DESCRIPTION |
|---|---|
events | List of UDM events to send TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
BatchSendResult | BatchSendResult with per-event results |
Source code in phytrace/agent.py
AgentConfig¶
AgentConfig dataclass ¶
AgentConfig(agent_id: str = 'phytrace-agent', agent_version: str = '0.1.0', source_id: str = '', source_type: SourceType = AMR, platform: str | None = None, fleet_id: str | None = None, site_id: str | None = None, organization_id: str | None = None, transport_type: str = 'http', endpoint: str = 'https://api.phycloud.phyware.io', phycloud_api_version: str = 'v1', api_key: str | None = None, timeout_sec: float = 30.0, license_token: str | None = None, license_grace_period_hours: int = DEFAULT_GRACE_PERIOD_HOURS, batching_enabled: bool = True, batch_max_size: int = 100, batch_max_age_ms: int = 1000, buffer_enabled: bool = True, buffer_path: str = '/var/lib/phytrace/buffer', buffer_max_size_mb: int = 1000, buffer_max_age_hours: int = 168, buffer_flush_interval_sec: float = 60.0, retry_max_retries: int = 5, retry_initial_delay_ms: int = 100, circuit_failure_threshold: int = 5, circuit_recovery_timeout_sec: float = 60.0, provenance_enabled: bool = True, signing_key: bytes | None = None, signing_key_id: str | None = None, signer: str | None = None, tpm_tcti: str | None = None, tpm_key_handle: int = DEFAULT_KEY_HANDLE, tpm_counter_index: int = DEFAULT_COUNTER_INDEX, tpm_boot_authority: str | None = None, tpm_boot_approvals: str | None = None, attestation_enabled: bool = False, attestation_interval_sec: float = 3600.0, attestation_pcrs: str = DEFAULT_PCRS, sequence_path: str | None = None, batch_signing_enabled: bool = False, batch_signing_max_size: int = 64, batch_signing_max_latency_ms: int = 500, heartbeat_enabled: bool = True, heartbeat_interval_sec: float = 60.0, validation_enabled: bool = True, validation_strict: bool = False)
Configuration for the PhyTrace Agent.