phi_core/lib.rs
1/*
2lib.rs — The crate root of yo-core (phi-core).
3
4RUST QUIRK: `mod` vs `use` — Declaration vs Import
5
6 `mod foo;` — "this crate has a module called foo, load it from foo.rs (or foo/mod.rs)"
7 Python analogy: nothing direct, but closest is the implicit __init__.py that
8 makes a directory a package. In Rust, you must explicitly declare every module.
9
10 `pub mod foo;` — same, but the module is publicly accessible to crate users.
11 Private modules (without `pub`) can still be used inside this crate.
12
13 `use foo::Bar;` — "bring Bar into scope by name" (no declaration, just aliasing)
14 Python analogy: `from foo import Bar`
15
16 `pub use foo::Bar;` — "bring Bar into scope AND re-export it as part of THIS module's public API"
17 Python analogy: `from foo import Bar` in __init__.py (making it top-level)
18
19RUST QUIRK: `pub use types::*;`
20
21The `*` glob re-export makes every public item in `types` available directly from `yo_core::`.
22So users can write `use yo_core::AgentTool` instead of `use yo_core::types::AgentTool`.
23This is a deliberate ergonomic choice — types are the most-used exports, so flattening them
24to the crate root reduces import noise.
25
26RUST QUIRK: `#[cfg(feature = "openapi")]`
27
28Feature flags gate optional compilation. The `openapi` feature is listed in Cargo.toml under
29`[features]`. Without it, the openapi module is completely absent from the compiled binary —
30zero size, zero compile time. This is Rust's equivalent of optional dependencies / extras.
31
32 Cargo.toml: [features] openapi = ["dep:utoipa"]
33 Enable: cargo build --features openapi
34 In code: #[cfg(feature = "openapi")] pub mod openapi;
35
36Architecture summary: the `pub use` lines below define the "public API surface" of phi-core.
37Everything a library user needs should be reachable without knowing internal module paths.
38*/
39
40pub mod agent_loop;
41pub mod agents;
42pub mod context;
43pub mod mcp;
44pub mod provider;
45pub mod session;
46pub mod tools;
47pub mod types;
48// retry.rs moved to provider/retry.rs
49// skills.rs moved to context/skills.rs
50
51pub mod config;
52
53// Feature-gated OpenAPI integration. Enabled with: cargo build --features openapi
54#[cfg(feature = "openapi")]
55pub mod openapi;
56
57// Re-export the most-used types at the crate root for ergonomic imports.
58// Users write `use phi_core::Agent` / `use phi_core::BasicAgent` instead of
59// navigating internal module paths.
60pub use agent_loop::evaluation::{
61 ElaborateEvaluation, LlmJudgeEvaluation, PickFirstEvaluation, TokenEfficientEvaluation,
62 TransparentEvaluation,
63};
64pub use agent_loop::{agent_loop, agent_loop_continue, agent_loop_parallel};
65pub use agents::SubAgentTool;
66pub use agents::{Agent, AgentProfile, BasicAgent, QueueMode};
67pub use config::{
68 agent_from_config, agent_from_config_with_registry, agents_from_config, parse_config,
69 parse_config_file, AgentConfig, ConfigError, ConfigFormat,
70};
71pub use context::skills::SkillSet;
72pub use context::{
73 build_context_from_session, compact_session_loops, BlockCompactionStrategy, CompactedSection,
74 CompactionBlock, CompactionConfig, CompactionScope, CompactionStrategy, ContextConfig,
75 ContextTracker, DefaultBlockCompaction, DefaultCompaction, TurnMap, TurnRange,
76};
77pub use provider::retry::RetryConfig;
78pub use session::{
79 delete_session, list_session_ids, load_session, load_sessions_for_agent, save_session,
80 ChildLoopRef, LoopConfigSnapshot, LoopEvent, LoopRecord, LoopStatus, ParallelGroupRecord,
81 Session, SessionError, SessionFormation, SessionRecorder, SessionRecorderConfig, SessionScope,
82 SpawnRef, Turn,
83};
84pub use types::*; // glob re-export: ALL public items from types become top-level exports